Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* RE: [PATCH 02/32] Introduce flexible array struct memcpy() helpers
       [not found]               ` <e1ea4926f105b456f6a86ce30a0380ee5f48fe6d.camel@sipsolutions.net>
@ 2022-05-06 11:15                 ` David Laight
  0 siblings, 0 replies; 4+ messages in thread
From: David Laight @ 2022-05-06 11:15 UTC (permalink / raw)
  To: 'Johannes Berg', Keith Packard, Kees Cook
  Cc: Christian Lamparter, Eli Cohen, K. Y. Srinivasan, Louis Peens,
	Wei Liu, Hulk Robot, Eugeniu Rosca, James Morris,
	xen-devel@lists.xenproject.org, Guenter Roeck, Marcel Holtmann,
	Al Viro, Kuniyuki Iwashima, Christian Brauner, Dmitry Kasatkin,
	Stephen Smalley, linux-usb@vger.kernel.org,
	linux-wireless@vger.kernel.org, John Keeping, Stefano Stabellini,
	Greg Kroah-Hartman, Andrew Morton, alsa-devel@alsa-project.org,
	Nick Desaulniers, Mimi Zohar, Max Filippov, Eric Dumazet,
	keyrings@vger.kernel.org, Gregory Greenman, Francis Laniel,
	Lars-Peter Clausen, Stephen Hemminger, Bradley Grove,
	Leon Romanovsky, Udipto Goswami, linux-xtensa@linux-xtensa.org,
	Baowen Zheng, selinux@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, Muchun Song, Boris Ostrovsky,
	linux-arm-kernel@lists.infradead.org, Daniel Axtens, Chris Zankel,
	Gustavo A . R . Silva, Jarkko Sakkinen,
	linux-integrity@vger.kernel.org, Cong Wang, David Gow, Tom Rix,
	Alexei Starovoitov, Nuno Sá, Luca Coelho,
	linux-hardening@vger.kernel.org, Marc Dionne, Frank Rowand,
	linux-afs@lists.infradead.org, Andrew Gabbasov,
	Dennis Dalessandro, linux-rdma@vger.kernel.org, Dexuan Cui,
	Simon Horman, Paolo Abeni, Serge E. Hallyn, Jens Axboe,
	Xiu Jianfeng, James E.J. Bottomley, Yang Yingliang,
	Hante Meuleman, Nathan Chancellor, Paul Moore, Mark Brown,
	Eric Paris, Dan Williams, Tadeusz Struk, Christian Göttsche,
	Franky Lin, Felipe Balbi, Arend van Spriel, Martin K. Petersen,
	Liam Girdwood, Stefan Richter, David S. Miller, Daniel Vetter,
	llvm@lists.linux.dev, Bjorn Andersson, David Howells,
	wcn36xx@lists.infradead.org, Vincenzo Frascino, Lee Jones,
	Steffen Klassert, linux1394-devel@lists.sourceforge.net,
	Herbert Xu, linux-scsi@vger.kernel.org, Russell King,
	Jason Gunthorpe, SHA-cyfmac-dev-list@infineon.com, Andy Gross,
	Jakub Kicinski, Andy Lavr, Haiyang Zhang,
	devicetree@vger.kernel.org, Johan Hedberg,
	linux-hyperv@vger.kernel.org, Kalle Valo, Rich Felker,
	Rob Herring, Luiz Augusto von Dentz, kunit-dev@googlegroups.com,
	Juergen Gross, brcm80211-dev-list.pdl@broadcom.com, Loic Poulain,
	netdev@vger.kernel.org, Takashi Iwai,
	linux-bluetooth@vger.kernel.org,
	linux-security-module@vger.kernel.org

From: Johannes Berg
> Sent: 05 May 2022 21:13
> On Thu, 2022-05-05 at 13:08 -0700, Keith Packard wrote:
> 
> 
> > I bet you've already considered the simpler form:
> >
> >         struct something *instance = mem_to_flex_dup(byte_array, count, GFP_KERNEL);
> >         if (IS_ERR(instance))
> >             return PTR_ERR(instance);
> >
> 
> Sadly, this doesn't work in any way because mem_to_flex_dup() needs to
> know at least the type, hence passing 'instance', which is simpler than
> passing 'struct something'.

You can use:
         struct something *instance;
         mem_to_flex_dup(instance, byte_array, count, GFP_KERNEL);
         if (IS_ERR(instance))
             return PTR_ERR(instance);
and have mem_to_flex_dup() (which must be a #define) update 'instance'.
(You can require &instance - and just precede all the uses with
an extra '*' to make it more obvious the variable is updated.
But there is little point requiring it be NULL.)

If you really want to define the variable mid-block you can use:
         mem_to_flex_dup(struct something *, instance, byte_array, count, GFP_KERNEL);

but I really hate having declarations anywhere other than the top of
a function because it makes them hard for the 'mk1 eyeball' to spot.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 19/32] afs: Use mem_to_flex_dup() with struct afs_acl
       [not found] ` <20220504014440.3697851-20-keescook@chromium.org>
@ 2022-05-12 21:41   ` David Howells
  2022-05-13 15:44     ` Kees Cook
  0 siblings, 1 reply; 4+ messages in thread
From: David Howells @ 2022-05-12 21:41 UTC (permalink / raw)
  To: Kees Cook
  Cc: Vincenzo Frascino, Christian Lamparter, Eli Cohen,
	K. Y. Srinivasan, Louis Peens, Wei Liu, Hulk Robot, James Morris,
	xen-devel, Guenter Roeck, Marcel Holtmann, Arend van Spriel,
	Al Viro, Kuniyuki Iwashima, Christian Brauner, Dmitry Kasatkin,
	Stephen Smalley, linux-usb, linux-wireless, John Keeping,
	Stefano Stabellini, Greg Kroah-Hartman, Andrew Morton, alsa-devel,
	Nick Desaulniers, Mimi Zohar, Max Filippov, Eric Dumazet,
	keyrings, Gregory Greenman, Francis Laniel, Lars-Peter Clausen,
	Stephen Hemminger, Bradley Grove, Leon Romanovsky, Udipto Goswami,
	linux-xtensa, Baowen Zheng, Johannes Berg, selinux, linux-arm-msm,
	Muchun Song, Boris Ostrovsky, linux-arm-kernel, Daniel Axtens,
	Chris Zankel, Gustavo A . R . Silva, Jarkko Sakkinen,
	linux-integrity, Cong Wang, David Gow, Tom Rix,
	Alexei Starovoitov, Nuno Sá, Luca Coelho, linux-hardening,
	Marc Dionne, Frank Rowand, linux-afs, Andrew Gabbasov,
	Dennis Dalessandro, linux-rdma, Dexuan Cui, Simon Horman,
	Paolo Abeni, Serge E. Hallyn, Jens Axboe, Xiu Jianfeng,
	James E.J. Bottomley, Yang Yingliang, Hante Meuleman,
	Nathan Chancellor, Paul Moore, Mark Brown, Eric Paris,
	Dan Williams, Tadeusz Struk, Christian Göttsche, Franky Lin,
	Felipe Balbi, Keith Packard, Martin K. Petersen, Liam Girdwood,
	Stefan Richter, David S. Miller, Daniel Vetter, llvm,
	Bjorn Andersson, David Howells, wcn36xx, Eugeniu Rosca, Lee Jones,
	Steffen Klassert, linux1394-devel, Herbert Xu, linux-scsi,
	Russell King, Jason Gunthorpe, SHA-cyfmac-dev-list, Andy Gross,
	Jakub Kicinski, Andy Lavr, Haiyang Zhang, devicetree,
	Johan Hedberg, linux-hyperv, Kalle Valo, Rich Felker, Rob Herring,
	Luiz Augusto von Dentz, kunit-dev, Juergen Gross,
	brcm80211-dev-list.pdl, Loic Poulain, netdev, Takashi Iwai,
	linux-bluetooth, linux-security-module, Johannes Berg


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 00/32] Introduce flexible array struct memcpy() helpers
       [not found] <20220504014440.3697851-1-keescook@chromium.org>
       [not found] ` <20220504014440.3697851-3-keescook@chromium.org>
       [not found] ` <20220504014440.3697851-20-keescook@chromium.org>
@ 2022-05-12 21:47 ` David Howells
  2 siblings, 0 replies; 4+ messages in thread
From: David Howells @ 2022-05-12 21:47 UTC (permalink / raw)
  To: Kees Cook
  Cc: Vincenzo Frascino, Christian Lamparter, Eli Cohen,
	K. Y. Srinivasan, Louis Peens, Wei Liu, Hulk Robot, James Morris,
	xen-devel, Guenter Roeck, Marcel Holtmann, Arend van Spriel,
	Al Viro, Kuniyuki Iwashima, Christian Brauner, Dmitry Kasatkin,
	Stephen Smalley, linux-usb, linux-wireless, John Keeping,
	Stefano Stabellini, Greg Kroah-Hartman, Andrew Morton, alsa-devel,
	Nick Desaulniers, Mimi Zohar, Max Filippov, Eric Dumazet,
	keyrings, Gregory Greenman, Francis Laniel, Lars-Peter Clausen,
	Stephen Hemminger, Bradley Grove, Leon Romanovsky, Udipto Goswami,
	linux-xtensa, Baowen Zheng, Johannes Berg, selinux, linux-arm-msm,
	Muchun Song, Boris Ostrovsky, linux-arm-kernel, Daniel Axtens,
	Chris Zankel, Jarkko Sakkinen, linux-integrity, Cong Wang,
	David Gow, Tom Rix, Alexei Starovoitov, Nuno Sá, Luca Coelho,
	linux-hardening, Marc Dionne, Frank Rowand, linux-afs,
	Andrew Gabbasov, Dennis Dalessandro, linux-rdma, Dexuan Cui,
	Simon Horman, Paolo Abeni, Serge E. Hallyn, Jens Axboe,
	Xiu Jianfeng, James E.J. Bottomley, Yang Yingliang,
	Hante Meuleman, Nathan Chancellor, Paul Moore, Mark Brown,
	Eric Paris, Dan Williams, Tadeusz Struk, Christian Göttsche,
	Franky Lin, Felipe Balbi, Keith Packard, Martin K. Petersen,
	Liam Girdwood, Stefan Richter, David S. Miller, Daniel Vetter,
	llvm, Bjorn Andersson, David Howells, wcn36xx, Eugeniu Rosca,
	Lee Jones, Steffen Klassert, linux1394-devel, Herbert Xu,
	linux-scsi, Russell King, Jason Gunthorpe, SHA-cyfmac-dev-list,
	Andy Gross, Jakub Kicinski, Andy Lavr, Haiyang Zhang, devicetree,
	Johan Hedberg, linux-hyperv, Kalle Valo, Rich Felker, Rob Herring,
	Luiz Augusto von Dentz, kunit-dev, Juergen Gross,
	brcm80211-dev-list.pdl, Loic Poulain, netdev, Takashi Iwai,
	linux-bluetooth, linux-security-module, Johannes Berg


Kees Cook <keescook@chromium.org> wrote:

> I'm happy to also point out that the conversions (patches 5+) are actually
> a net reduction in lines of code:
>  49 files changed, 154 insertions(+), 244 deletions(-)

That doesn't mean that it's actually code that's clearer to read.  I would say
that it's actually less clear.  In a bunch of places, you've done something
like:

-	e = kmalloc(...);
-	if (!e)
+	if (__mem_to_flex_dup(&e, ...))

The problem is that, to me at least, it looks like:

-	e = kmalloc(...);
-	if (kmalloc failed)
+	if (__mem_to_flex_dup(&e, ...) succeeded)

David


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 19/32] afs: Use mem_to_flex_dup() with struct afs_acl
  2022-05-12 21:41   ` [PATCH 19/32] afs: Use mem_to_flex_dup() with struct afs_acl David Howells
@ 2022-05-13 15:44     ` Kees Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2022-05-13 15:44 UTC (permalink / raw)
  To: David Howells
  Cc: Vincenzo Frascino, Christian Lamparter, Eli Cohen,
	K. Y. Srinivasan, Louis Peens, Wei Liu, Hulk Robot, James Morris,
	xen-devel, Guenter Roeck, Arend van Spriel, Al Viro,
	Kuniyuki Iwashima, Christian Brauner, Dmitry Kasatkin,
	Stephen Smalley, linux-usb, linux-wireless, John Keeping,
	Stefano Stabellini, Greg Kroah-Hartman, Andrew Morton, alsa-devel,
	Nick Desaulniers, Mimi Zohar, Max Filippov, Eric Dumazet,
	keyrings, Gregory Greenman, Francis Laniel, Lars-Peter Clausen,
	Stephen Hemminger, Bradley Grove, Leon Romanovsky, Udipto Goswami,
	linux-xtensa, Baowen Zheng, Johannes Berg, selinux, linux-arm-msm,
	Muchun Song, Boris Ostrovsky, linux-arm-kernel, Daniel Axtens,
	Chris Zankel, Gustavo A . R . Silva, Jarkko Sakkinen,
	linux-integrity, Cong Wang, David Gow, Tom Rix,
	Alexei Starovoitov, Nuno Sá, Luca Coelho, linux-hardening,
	Marc Dionne, Frank Rowand, linux-afs, Andrew Gabbasov,
	Dennis Dalessandro, linux-rdma, Dexuan Cui, Simon Horman,
	Paolo Abeni, Serge E. Hallyn, Jens Axboe, Xiu Jianfeng,
	Marcel Holtmann, Yang Yingliang, Hante Meuleman,
	Nathan Chancellor, Paul Moore, Mark Brown, Eric Paris,
	Dan Williams, Tadeusz Struk, Christian Göttsche, Franky Lin,
	Felipe Balbi, Keith Packard, Martin K. Petersen, Haiyang Zhang,
	Liam Girdwood, Stefan Richter, David S. Miller, Daniel Vetter,
	llvm, Bjorn Andersson, wcn36xx, Eugeniu Rosca, Lee Jones,
	Steffen Klassert, linux1394-devel, Herbert Xu, linux-scsi,
	Russell King, Jason Gunthorpe, SHA-cyfmac-dev-list, Andy Gross,
	Jakub Kicinski, Andy Lavr, James E.J. Bottomley, devicetree,
	Johan Hedberg, linux-hyperv, Kalle Valo, Rich Felker, Rob Herring,
	Luiz Augusto von Dentz, kunit-dev, Juergen Gross,
	brcm80211-dev-list.pdl, Loic Poulain, netdev, Takashi Iwai,
	linux-bluetooth, linux-security-module, Johannes Berg

On Thu, May 12, 2022 at 10:41:05PM +0100, David Howells wrote:
> 
> 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.

Other threads discussed this too. I'm hoping to have something more
flexible (pardon the pun) in v2.

> [...]
> or:
> 
> 	ret = mem_to_flex_dup(&acl, buffer, size, GFP_KERNEL);
> 	if (ret < 0)
> 
> (or use != 0 rather than < 0)

Sure, I can make the tests more explicit. The kerndoc, etc all shows it's
using < 0 for errors.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-16  8:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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   ` [PATCH 19/32] afs: Use mem_to_flex_dup() with struct afs_acl David Howells
2022-05-13 15:44     ` Kees Cook
2022-05-12 21:47 ` [PATCH 00/32] Introduce flexible array struct memcpy() helpers David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox