Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp487557lqp; Tue, 11 Jun 2024 10:00:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUEUzKeDclT8oK8NZCStDsq+o2LmiApnUIvGl9WRrk3MY44e7o2EtLDiIXjgj5JEVtNbqqi/Gq6QDaqzK+G/pR3SQWzaMw1vMzvzh0jmQ== X-Google-Smtp-Source: AGHT+IEFSYDDdyI9/RHBTO4JwK9jQlI4zEEtUI6aCMUiL7hnAW4QtsEY1pQZfv20IiWu4u9Jez64 X-Received: by 2002:a67:f744:0:b0:48c:4020:4354 with SMTP id ada2fe7eead31-48c402048ddmr9354604137.5.1718125240193; Tue, 11 Jun 2024 10:00:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718125240; cv=pass; d=google.com; s=arc-20160816; b=aRXOSd5iGLXvLGMYAGXUWizH9zHLqBsojVa5SbTmkb0ttYdoSp85p/9pIYDvurnKPD vLN07hMrLDIAM0hIJYyAAQeKK2n5OGWhsfWI86A0tDzP1NEdtGi+ImTVmH97fHWejtsR kZHlusYzlCo47k4QPnDfuwyhfHhnGAf5toVu23cPVqIN2ZSRbE628Ga1Cz9A5xIz85xR ftwLJ9fXtn7MXZazQ6mComyC+or2BZgQv9gw8QsErFKkujzWZPDlN1HfgA55/Til51gC y7NGWIkmqDc8rxAG5fiNwCpPISTCq+lADqqDDgp78T26Ll6ZYTIF+wzhzCNHKrKW7h5d T/Dw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=zljMbUECpjEoEjlrYedqr50OhHK6pcp8SvIHGkSDEDg=; fh=i9RUlcSj9Us95OtlwWEB5vXf2cl/nFzJtTJDFMCv3co=; b=s77nL85wqS11zyAP0sC2Rhv3gRra9Bqvgot35LBCMC9D39HqkPf3KQBI8XjVYxWR72 K5ujdNyUDDvIKjEB1BtvnGajx96Ds62B+7H/VqZ16qM9JENlnvaNuZROuqZxvBbnqTjF K9WeSr8w/a2+pOduR+OPFNUO/HJZIuJ8HvSDFKTuzFleOZTi9UN9ezXcktyLNsZl/l6u 7Tcp4zbP/himI+bXE8XWtkfa098XUV6d/PBhoGSqV16VjN1TX2DrQPqVEp8UYK+4vj+R EBYofPEvGphYl+OavdaspbO+/wsF+TcqyhblWyQw1UtXpLNYT3YPhCD5SVfJKbVKBo3A BQ1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=brD3ms6z; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-210299-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210299-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ada2fe7eead31-48c52a3f044si1361591137.66.2024.06.11.10.00.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 10:00:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210299-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=brD3ms6z; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-210299-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210299-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D86631C24F2F for ; Tue, 11 Jun 2024 16:58:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E5CF85B5B6; Tue, 11 Jun 2024 16:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="brD3ms6z" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2B7654F8C; Tue, 11 Jun 2024 16:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718125042; cv=none; b=ZlvJJKdpti2kh7TGw30MwyYA7w93bSAaR3eCufIXfSzWEapsxQdeUDQhLyjgOr/2gL9juX+5KQpj8YaaMeUP4c8DNzz2RARcRHereBqpZTs7QrW+3sDH+WvElBer7HfIL/NUkitz5N33OU5PkFrwIseMOkbf4R4VTFTNXPcBKo0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718125042; c=relaxed/simple; bh=tHF+I96GJM1DzMeNe73SXmMclgaDAk6heGWpVzWBfTM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=g5vDwyonZ9qyHwYs3NFVB5tw4FtJivTcZU5lP4mfasMmTX6Shjkt/JGhJiQ5mWZIB83X5TYLhhvSHyucGQCjlJdNRb/gaf1Cay6iwN+E+OGLIJ7Ag7HbDqSiXNv5qdhlxZLnMMMbD4XFvsMYka51FxK8x4kbT8gipq90AR6TqW8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=brD3ms6z; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5479BC2BD10; Tue, 11 Jun 2024 16:57:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718125041; bh=tHF+I96GJM1DzMeNe73SXmMclgaDAk6heGWpVzWBfTM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=brD3ms6zQ1YOwd+qZdO7hJFbRuL5RewFTcIduEDgHxJi+AszN70l5plDVBVOOeGYB bPJTKc39Jll+ArjvI8Bd6q0h5ayJ22AK9QIiGO/AIFj+npQPi6g7aVEwM7wKQ5s8Et xx3yE1vcjcPCCfOPMkbumaO/uPIEeL3T3mWYPlHYiDzFsnSPaiAHRMEgIMex9w/E/4 GoHGojEfMX65I+E0f+Z59Xn4OJuBuBbET0OjcYAVSR78et+FAnseJOoEXKD/qUi3Dl s5lf6xNqdFoTjLXV1B3MjBymNHKHvdgQj/X16puDSz9K933USqNV6ts7vW1pL1DJoi y3ubVi1cI0wvg== Date: Tue, 11 Jun 2024 18:57:16 +0200 From: Benjamin Tissoires To: Alexei Starovoitov Cc: Shuah Khan , Jiri Kosina , Jonathan Corbet , Alexei Starovoitov , "open list:KERNEL SELFTEST FRAMEWORK" , LKML , bpf , "open list:HID CORE LAYER" , "open list:DOCUMENTATION" Subject: Re: [PATCH HID v3 15/16] HID: bpf: rework hid_bpf_ops_btf_struct_access Message-ID: References: <20240608-hid_bpf_struct_ops-v3-0-6ac6ade58329@kernel.org> <20240608-hid_bpf_struct_ops-v3-15-6ac6ade58329@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Jun 10 2024, Alexei Starovoitov wrote: > On Sat, Jun 8, 2024 at 2:01 AM Benjamin Tissoires wrote: > > > > The idea is to provide a list of stucts and their editable fields. > > > > Currently no functional changes are introduced here, we will add some > > more writeable fields in the next patch. > > > > Signed-off-by: Benjamin Tissoires > > > > --- > > > > changes in v3: > > - rewrote WRITE_RANGE macro to not deal with offset from the caller side > > > > new in v2 > > --- > > drivers/hid/bpf/hid_bpf_struct_ops.c | 91 +++++++++++++++++++++++++++--------- > > 1 file changed, 69 insertions(+), 22 deletions(-) > > > > diff --git a/drivers/hid/bpf/hid_bpf_struct_ops.c b/drivers/hid/bpf/hid_bpf_struct_ops.c > > index 056d05d96962..b14eccb121e0 100644 > > --- a/drivers/hid/bpf/hid_bpf_struct_ops.c > > +++ b/drivers/hid/bpf/hid_bpf_struct_ops.c > > @@ -16,6 +16,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include "hid_bpf_dispatch.h" > > > > @@ -52,40 +53,86 @@ static int hid_bpf_ops_check_member(const struct btf_type *t, > > return 0; > > } > > > > +struct hid_bpf_offset_write_range { > > + const char *struct_name; > > + u32 struct_length; > > + u32 start; > > + u32 end; > > +}; > > + > > static int hid_bpf_ops_btf_struct_access(struct bpf_verifier_log *log, > > const struct bpf_reg_state *reg, > > int off, int size) > > { > > - const struct btf_type *state; > > - const struct btf_type *t; > > - s32 type_id; > > +#define WRITE_RANGE(_name, _field, _is_string) \ > > + { \ > > + .struct_name = #_name, \ > > + .struct_length = sizeof(struct _name), \ > > + .start = offsetof(struct _name, _field), \ > > + .end = offsetofend(struct _name, _field) - !!(_is_string), > > so it works because char name[128]; had last byte as zero > before prog writes into it (in addition to potentially having > earlier 0 bytes), so the string is guaranteed > to be null-terminated regardless of what prog writes into it. > Right? Yeah, struct hid_device is created through hid_allocate_device(), which does a kzalloc. Then all operations are supposedly safe in the current transport layers, so the last byte should always be \0. > > Overall: > Acked-by: Alexei Starovoitov Thanks a lot. I might send a v4 or not depending if I get other reviews, but I'll make sure to take your nitpick in 3/16 into account (cast kdata/udate in the beginning of the function to make the lines shorter and less verbose). Cheers, Benjamin