lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPhsuW5mKPT+Vw4FVFBokwnY1kkCm9i_HA3Pd2DUznHJfqV+4A@mail.gmail.com>
Date:   Fri, 18 Mar 2022 14:20:56 -0700
From:   Song Liu <song@...nel.org>
To:     Benjamin Tissoires <benjamin.tissoires@...hat.com>
Cc:     Greg KH <gregkh@...uxfoundation.org>,
        Jiri Kosina <jikos@...nel.org>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>, Shuah Khan <shuah@...nel.org>,
        Dave Marchevsky <davemarchevsky@...com>,
        Joe Stringer <joe@...ium.io>, Jonathan Corbet <corbet@....net>,
        Tero Kristo <tero.kristo@...ux.intel.com>,
        open list <linux-kernel@...r.kernel.org>,
        "open list:HID CORE LAYER" <linux-input@...r.kernel.org>,
        Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
        linux-kselftest@...r.kernel.org,
        Linux Doc Mailing List <linux-doc@...r.kernel.org>
Subject: Re: [PATCH bpf-next v3 13/17] HID: bpf: implement hid_bpf_get|set_bits

On Fri, Mar 18, 2022 at 9:18 AM Benjamin Tissoires
<benjamin.tissoires@...hat.com> wrote:
>
> Export implement() outside of hid-core.c and use this and

Maybe rename implement() to something that makes sense?

> hid_field_extract() to implement the helprs for hid-bpf.
>
> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@...hat.com>
>
> ---
>
> changes in v3:
> - renamed hid_{get|set}_data into hid_{get|set}_bits
>
> changes in v2:
> - split the series by bpf/libbpf/hid/selftests and samples
> - allow for n > 32, by relying on memcpy
> ---
>  drivers/hid/hid-bpf.c  | 29 +++++++++++++++++++++++++++++
>  drivers/hid/hid-core.c |  4 ++--
>  include/linux/hid.h    |  2 ++
>  3 files changed, 33 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hid/hid-bpf.c b/drivers/hid/hid-bpf.c
> index 45c87ff47324..650dd5e54919 100644
> --- a/drivers/hid/hid-bpf.c
> +++ b/drivers/hid/hid-bpf.c
> @@ -122,6 +122,33 @@ static void hid_bpf_array_detach(struct hid_device *hdev, enum bpf_hid_attach_ty
>         }
>  }
>
> +static int hid_bpf_get_bits(struct hid_device *hdev, u8 *buf, size_t buf_size, u64 offset, u32 n,
> +                           u32 *data)
> +{
> +       if (n > 32)
> +               return -EINVAL;
> +
> +       if (((offset + n) >> 3) >= buf_size)
> +               return -E2BIG;
> +
> +       *data = hid_field_extract(hdev, buf, offset, n);
> +       return n;
> +}
> +
> +static int hid_bpf_set_bits(struct hid_device *hdev, u8 *buf, size_t buf_size, u64 offset, u32 n,
> +                           u32 data)
> +{
> +       if (n > 32)
> +               return -EINVAL;
> +
> +       if (((offset + n) >> 3) >= buf_size)
> +               return -E2BIG;
> +
> +       /* data must be a pointer to a u32 */
> +       implement(hdev, buf, offset, n, data);
> +       return n;
> +}
> +
>  static int hid_bpf_run_progs(struct hid_device *hdev, struct hid_bpf_ctx_kern *ctx)
>  {
>         enum bpf_hid_attach_type type;
> @@ -223,6 +250,8 @@ int __init hid_bpf_module_init(void)
>                 .pre_link_attach = hid_bpf_pre_link_attach,
>                 .post_link_attach = hid_bpf_post_link_attach,
>                 .array_detach = hid_bpf_array_detach,
> +               .hid_get_bits = hid_bpf_get_bits,
> +               .hid_set_bits = hid_bpf_set_bits,
>         };
>
>         bpf_hid_set_hooks(&hooks);
> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index 3182c39db006..4f669dcddc08 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -1416,8 +1416,8 @@ static void __implement(u8 *report, unsigned offset, int n, u32 value)
>         }
>  }
>
> -static void implement(const struct hid_device *hid, u8 *report,
> -                     unsigned offset, unsigned n, u32 value)
> +void implement(const struct hid_device *hid, u8 *report, unsigned int offset, unsigned int n,
> +              u32 value)
>  {
>         if (unlikely(n > 32)) {
>                 hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
> diff --git a/include/linux/hid.h b/include/linux/hid.h
> index 66d949d10b78..7454e844324c 100644
> --- a/include/linux/hid.h
> +++ b/include/linux/hid.h
> @@ -944,6 +944,8 @@ bool hid_compare_device_paths(struct hid_device *hdev_a,
>  s32 hid_snto32(__u32 value, unsigned n);
>  __u32 hid_field_extract(const struct hid_device *hid, __u8 *report,
>                      unsigned offset, unsigned n);
> +void implement(const struct hid_device *hid, u8 *report, unsigned int offset, unsigned int n,
> +              u32 value);
>
>  #ifdef CONFIG_PM
>  int hid_driver_suspend(struct hid_device *hdev, pm_message_t state);
> --
> 2.35.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ