Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Kees Cook <keescook@chromium.org>
Cc: "Vincenzo Frascino" <vincenzo.frascino@arm.com>,
	"Christian Lamparter" <chunkeey@googlemail.com>,
	"Eli Cohen" <elic@nvidia.com>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	"Louis Peens" <louis.peens@corigine.com>,
	"Wei Liu" <wei.liu@kernel.org>, "Hulk Robot" <hulkci@huawei.com>,
	"James Morris" <jmorris@namei.org>,
	xen-devel@lists.xenproject.org,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Marcel Holtmann" <marcel@holtmann.org>,
	"Arend van Spriel" <aspriel@gmail.com>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	"Kuniyuki Iwashima" <kuniyu@amazon.co.jp>,
	"Christian Brauner" <brauner@kernel.org>,
	"Dmitry Kasatkin" <dmitry.kasatkin@gmail.com>,
	"Stephen Smalley" <stephen.smalley.work@gmail.com>,
	linux-usb@vger.kernel.org, linux-wireless@vger.kernel.org,
	"John Keeping" <john@metanate.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	alsa-devel@alsa-project.org,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Mimi Zohar" <zohar@linux.ibm.com>,
	"Max Filippov" <jcmvbkbc@gmail.com>,
	"Eric Dumazet" <edumazet@google.com>,
	keyrings@vger.kernel.org,
	"Gregory Greenman" <gregory.greenman@intel.com>,
	"Francis Laniel" <laniel_francis@privacyrequired.com>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Stephen Hemminger" <sthemmin@microsoft.com>,
	"Bradley Grove" <linuxdrivers@attotech.com>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Udipto Goswami" <quic_ugoswami@quicinc.com>,
	linux-xtensa@linux-xtensa.org,
	"Baowen Zheng" <baowen.zheng@corigine.com>,
	"Johannes Berg" <johannes.berg@intel.com>,
	selinux@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	"Muchun Song" <songmuchun@bytedance.com>,
	"Boris Ostrovsky" <boris.ostrovsky@oracle.com>,
	linux-arm-kernel@lists.infradead.org,
	"Daniel Axtens" <dja@axtens.net>,
	"Chris Zankel" <chris@zankel.net>,
	"Gustavo A . R . Silva" <gustavoars@kernel.org>,
	"Jarkko Sakkinen" <jarkko@kernel.org>,
	linux-integrity@vger.kernel.org,
	"Cong Wang" <cong.wang@bytedance.com>,
	"David Gow" <davidgow@google.com>, "Tom Rix" <trix@redhat.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Luca Coelho" <luciano.coelho@intel.com>,
	linux-hardening@vger.kernel.org,
	"Marc Dionne" <marc.dionne@auristor.com>,
	"Frank Rowand" <frowand.list@gmail.com>,
	linux-afs@lists.infradead.org,
	"Andrew Gabbasov" <andrew_gabbasov@mentor.com>,
	"Dennis Dalessandro" <dennis.dalessandro@cornelisnetworks.com>,
	linux-rdma@vger.kernel.org, "Dexuan Cui" <decui@microsoft.com>,
	"Simon Horman" <simon.horman@corigine.com>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"Jens Axboe" <axboe@kernel.dk>,
	"Xiu Jianfeng" <xiujianfeng@huawei.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Yang Yingliang" <yangyingliang@huawei.com>,
	"Hante Meuleman" <hante.meuleman@broadcom.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Paul Moore" <paul@paul-moore.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Eric Paris" <eparis@parisplace.org>,
	"Dan Williams" <dan.j.williams@intel.com>,
	"Tadeusz Struk" <tadeusz.struk@linaro.org>,
	"Christian Göttsche" <cgzones@googlemail.com>,
	"Franky Lin" <franky.lin@broadcom.com>,
	"Felipe Balbi" <balbi@kernel.org>,
	"Keith Packard" <keithp@keithp.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Stefan Richter" <stefanr@s5r6.in-berlin.de>,
	"David S. Miller" <davem@davemloft.net>,
	"Daniel Vetter" <daniel.vetter@ffwll.ch>,
	llvm@lists.linux.dev,
	"Bjorn Andersson" <bjorn.andersson@linaro.org>,
	"David Howells" <dhowells@redhat.com>,
	wcn36xx@lists.infradead.org,
	"Eugeniu Rosca" <erosca@de.adit-jv.com>,
	"Lee Jones" <lee.jones@linaro.org>,
	"Steffen Klassert" <steffen.klassert@secunet.com>,
	linux1394-devel@lists.sourceforge.net,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	linux-scsi@vger.kernel.org,
	"Russell King" <linux@armlinux.org.uk>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	SHA-cyfmac-dev-list@infineon.com,
	"Andy Gross" <agross@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Andy Lavr" <andy.lavr@gmail.com>,
	"Haiyang Zhang" <haiyangz@microsoft.com>,
	devicetree@vger.kernel.org,
	"Johan Hedberg" <johan.hedberg@gmail.com>,
	linux-hyperv@vger.kernel.org, "Kalle Valo" <kvalo@kernel.org>,
	"Rich Felker" <dalias@aerifal.cx>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Luiz Augusto von Dentz" <luiz.dentz@gmail.com>,
	kunit-dev@googlegroups.com, "Juergen Gross" <jgross@suse.com>,
	brcm80211-dev-list.pdl@broadcom.com,
	"Loic Poulain" <loic.poulain@linaro.org>,
	netdev@vger.kernel.org, "Takashi Iwai" <tiwai@suse.com>,
	linux-bluetooth@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	"Johannes Berg" <johannes@sipsolutions.net>
Subject: Re: [PATCH 19/32] afs: Use mem_to_flex_dup() with struct afs_acl
Date: Thu, 12 May 2022 22:41:05 +0100	[thread overview]
Message-ID: <898803.1652391665@warthog.procyon.org.uk> (raw)
In-Reply-To: <20220504014440.3697851-20-keescook@chromium.org>


Kees Cook <keescook@chromium.org> wrote:

>  struct afs_acl {
> -	u32	size;
> -	u8	data[];
> +	DECLARE_FLEX_ARRAY_ELEMENTS_COUNT(u32, size);
> +	DECLARE_FLEX_ARRAY_ELEMENTS(u8, data);
>  };

Oof...  That's really quite unpleasant syntax.  Is it not possible to have
mem_to_flex_dup() and friends work without that?  You are telling them the
fields they have to fill in.

> +	struct afs_acl *acl = NULL;
>  
> -	acl = kmalloc(sizeof(*acl) + size, GFP_KERNEL);
> -	if (!acl) {
> +	if (mem_to_flex_dup(&acl, buffer, size, GFP_KERNEL)) {

Please don't do that.  Either do:

	acl = mem_to_flex_dup(buffer, size, GFP_KERNEL);
	if (!acl)

or:

	acl = mem_to_flex_dup(buffer, size, GFP_KERNEL);
	if (IS_ERR(acl))

Please especially don't make it that an apparent 'true' return indicates an
error.  If you absolutely must return the acl pointer through the argument
list (presumably because it's actually a macro), make it return false on
failure:

	if (!mem_to_flex_dup(&acl, buffer, size, GFP_KERNEL))

or return and explicitly check for an error code:

	if (mem_to_flex_dup(&acl, buffer, size, GFP_KERNEL) < 0)

or:

	ret = mem_to_flex_dup(&acl, buffer, size, GFP_KERNEL);
	if (ret < 0)

(or use != 0 rather than < 0)

David


  parent reply	other threads:[~2022-05-16  8:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220504014440.3697851-1-keescook@chromium.org>
     [not found] ` <20220504014440.3697851-3-keescook@chromium.org>
     [not found]   ` <d3b73d80f66325fdfaf2d1f00ea97ab3db03146a.camel@sipsolutions.net>
     [not found]     ` <202205040819.DEA70BD@keescook>
     [not found]       ` <970a674df04271b5fd1971b495c6b11a996c20c2.camel@sipsolutions.net>
     [not found]         ` <871qx8qabo.fsf@keithp.com>
     [not found]           ` <202205051228.4D5B8CD624@keescook>
     [not found]             ` <87pmkrpwrs.fsf@keithp.com>
     [not found]               ` <e1ea4926f105b456f6a86ce30a0380ee5f48fe6d.camel@sipsolutions.net>
2022-05-06 11:15                 ` [PATCH 02/32] Introduce flexible array struct memcpy() helpers David Laight
     [not found] ` <20220504014440.3697851-20-keescook@chromium.org>
2022-05-12 21:41   ` David Howells [this message]
2022-05-13 15:44     ` [PATCH 19/32] afs: Use mem_to_flex_dup() with struct afs_acl Kees Cook
2022-05-12 21:47 ` [PATCH 00/32] Introduce flexible array struct memcpy() helpers David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=898803.1652391665@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=SHA-cyfmac-dev-list@infineon.com \
    --cc=agross@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=andrew_gabbasov@mentor.com \
    --cc=andy.lavr@gmail.com \
    --cc=aspriel@gmail.com \
    --cc=ast@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=balbi@kernel.org \
    --cc=baowen.zheng@corigine.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=boris.ostrovsky@oracle.com \
    --cc=brauner@kernel.org \
    --cc=brcm80211-dev-list.pdl@broadcom.com \
    --cc=broonie@kernel.org \
    --cc=cgzones@googlemail.com \
    --cc=chris@zankel.net \
    --cc=chunkeey@googlemail.com \
    --cc=cong.wang@bytedance.com \
    --cc=dalias@aerifal.cx \
    --cc=dan.j.williams@intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=davem@davemloft.net \
    --cc=davidgow@google.com \
    --cc=decui@microsoft.com \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dja@axtens.net \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=edumazet@google.com \
    --cc=elic@nvidia.com \
    --cc=eparis@parisplace.org \
    --cc=erosca@de.adit-jv.com \
    --cc=franky.lin@broadcom.com \
    --cc=frowand.list@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gregory.greenman@intel.com \
    --cc=gustavoars@kernel.org \
    --cc=haiyangz@microsoft.com \
    --cc=hante.meuleman@broadcom.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=hulkci@huawei.com \
    --cc=jarkko@kernel.org \
    --cc=jcmvbkbc@gmail.com \
    --cc=jejb@linux.ibm.com \
    --cc=jgg@ziepe.ca \
    --cc=jgross@suse.com \
    --cc=jmorris@namei.org \
    --cc=johan.hedberg@gmail.com \
    --cc=johannes.berg@intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=john@metanate.com \
    --cc=keescook@chromium.org \
    --cc=keithp@keithp.com \
    --cc=keyrings@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=kuniyu@amazon.co.jp \
    --cc=kvalo@kernel.org \
    --cc=kys@microsoft.com \
    --cc=laniel_francis@privacyrequired.com \
    --cc=lars@metafoo.de \
    --cc=lee.jones@linaro.org \
    --cc=leon@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux-xtensa@linux-xtensa.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    --cc=linux@armlinux.org.uk \
    --cc=linux@roeck-us.net \
    --cc=linuxdrivers@attotech.com \
    --cc=llvm@lists.linux.dev \
    --cc=loic.poulain@linaro.org \
    --cc=louis.peens@corigine.com \
    --cc=luciano.coelho@intel.com \
    --cc=luiz.dentz@gmail.com \
    --cc=marc.dionne@auristor.com \
    --cc=marcel@holtmann.org \
    --cc=martin.petersen@oracle.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=pabeni@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=quic_ugoswami@quicinc.com \
    --cc=robh+dt@kernel.org \
    --cc=selinux@vger.kernel.org \
    --cc=serge@hallyn.com \
    --cc=simon.horman@corigine.com \
    --cc=songmuchun@bytedance.com \
    --cc=sstabellini@kernel.org \
    --cc=stefanr@s5r6.in-berlin.de \
    --cc=steffen.klassert@secunet.com \
    --cc=stephen.smalley.work@gmail.com \
    --cc=sthemmin@microsoft.com \
    --cc=tadeusz.struk@linaro.org \
    --cc=tiwai@suse.com \
    --cc=trix@redhat.com \
    --cc=vincenzo.frascino@arm.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wcn36xx@lists.infradead.org \
    --cc=wei.liu@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    --cc=xiujianfeng@huawei.com \
    --cc=yangyingliang@huawei.com \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox