From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 8E0B42F2C for ; Thu, 12 May 2022 21:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652391688; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YX4qZOz+9WbIDFanSGeueshT1smpwyQHiwCB0mvZIgg=; b=UB0zHdp4klqAngjDbOqmkofzodTQqJrA4GB7Na4o6Xl/gchGA5HDiTJ5iXOV6YXLK5YI0m 3ZAYGxnZwtmMcvOlfbi0V6kdThfpGxt6StW0v+SEb5lxJ9sdpdtBnGZ6jC73eNf5Tluvrl DAPKsCGFHYjcHTS4HfE/Kp0t7IyfCtw= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-651-_lIP8Q0uMUaVvsz49D3spw-1; Thu, 12 May 2022 17:41:24 -0400 X-MC-Unique: _lIP8Q0uMUaVvsz49D3spw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E9268296A609; Thu, 12 May 2022 21:41:22 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.37.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E2C7416156; Thu, 12 May 2022 21:41:05 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <20220504014440.3697851-20-keescook@chromium.org> References: <20220504014440.3697851-20-keescook@chromium.org> <20220504014440.3697851-1-keescook@chromium.org> To: Kees Cook Cc: "Gustavo A . R . Silva" , David Howells , Marc Dionne , linux-afs@lists.infradead.org, Alexei Starovoitov , alsa-devel@alsa-project.org, Al Viro , Andrew Gabbasov , Andrew Morton , Andy Gross , Andy Lavr , Arend van Spriel , Baowen Zheng , Bjorn Andersson , Boris Ostrovsky , Bradley Grove , brcm80211-dev-list.pdl@broadcom.com, Christian Brauner , Christian =?utf-8?Q?G=C3=B6ttsche?= , Christian Lamparter , Chris Zankel , Cong Wang , Daniel Axtens , Daniel Vetter , Dan Williams , David Gow , "David S. Miller" , Dennis Dalessandro , devicetree@vger.kernel.org, Dexuan Cui , Dmitry Kasatkin , Eli Cohen , Eric Dumazet , Eric Paris , Eugeniu Rosca , Felipe Balbi , Francis Laniel , Frank Rowand , Franky Lin , Greg Kroah-Hartman , Gregory Greenman , Guenter Roeck , Haiyang Zhang , Hante Meuleman , Herbert Xu , Hulk Robot , Jakub Kicinski , "James E.J. Bottomley" , James Morris , Jarkko Sakkinen , Jaroslav Kysela , Jason Gunthorpe , Jens Axboe , Johan Hedberg , Johannes Berg , Johannes Berg , John Keeping , Juergen Gross , Kalle Valo , Keith Packard , keyrings@vger.kernel.org, kunit-dev@googlegroups.com, Kuniyuki Iwashima , "K. Y. Srinivasan" , Lars-Peter Clausen , Lee Jones , Leon Romanovsky , Liam Girdwood , linux1394-devel@lists.sourceforge.net, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-hardening@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-integrity@vger.kernel.org, linux-rdma@vger.kernel.org, linux-scsi@vger.kernel.org, linux-security-module@vger.kernel.org, linux-usb@vger.kernel.org, linux-wireless@vger.kernel.org, linux-xtensa@linux-xtensa.org, llvm@lists.linux.dev, Loic Poulain , Louis Peens , Luca Coelho , Luiz Augusto von Dentz , Marcel Holtmann , Mark Brown , "Martin K. Petersen" , Max Filippov , Mimi Zohar , Muchun Song , Nathan Chancellor , netdev@vger.kernel.org, Nick Desaulniers , Nuno =?utf-8?Q?S=C3=A1?= , Paolo Abeni , Paul Moore , Rich Felker , Rob Herring , Russell King , selinux@vger.kernel.org, "Serge E. Hallyn" , SHA-cyfmac-dev-list@infineon.com, Simon Horman , Stefano Stabellini , Stefan Richter , Steffen Klassert , Stephen Hemminger , Stephen Smalley , Tadeusz Struk , Takashi Iwai , Tom Rix , Udipto Goswami , Vincenzo Frascino , wcn36xx@lists.infradead.org, Wei Liu , xen-devel@lists.xenproject.org, Xiu Jianfeng , Yang Yingliang Subject: Re: [PATCH 19/32] afs: Use mem_to_flex_dup() with struct afs_acl Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 12 May 2022 22:41:05 +0100 Message-ID: <898803.1652391665@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dhowells@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Kees Cook 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31104C433F5 for ; Mon, 16 May 2022 08:04:46 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 5923F168C; Mon, 16 May 2022 10:03:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5923F168C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1652688284; bh=tHRod8Mb/dNdpaU9bJxoRk0gP+S4QZJwBCDRVa3SBEE=; h=From:In-Reply-To:References:To:Subject:Date:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=IaHzDb+LxpEBNY+xA9e+5xqO9JZc8TbGE0n45oc/VoicH0VvGEUWmCbAqPMsD5XTx JLD2f/q7d11CagZlIjaqbIPi91lEGHBVR6w3YvHdmy4J8b/rDMyn7VmIT+5XzKws2B U4yM/SyMoLaxxd+rhc8Do1UTHmcFgPPHZfY7pQks= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id E0364F8012F; Mon, 16 May 2022 10:03:53 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 19D77F80245; Thu, 12 May 2022 23:41:40 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 1FE49F8010B for ; Thu, 12 May 2022 23:41:34 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 1FE49F8010B Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VsZCGTaO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652391693; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YX4qZOz+9WbIDFanSGeueshT1smpwyQHiwCB0mvZIgg=; b=VsZCGTaOehKMe9DAN5vRKReHDpdASjDneVj6I7appexMgKL42ejf9XhVfOGpyF/1WJB0U9 vFeWAv3oyl5x8xP9tbErqG2z/Qr55hy/rVWhFZ1gRLk5GqsZ/ZdkPYI8tO+jp9frCaKSpo M9BatbtU/r0TFrnT+lACJvPbipibMEY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-472-4ZGPbZ3WPveqDfw1Mo23Iw-1; Thu, 12 May 2022 17:41:25 -0400 X-MC-Unique: 4ZGPbZ3WPveqDfw1Mo23Iw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E8EC4801E80; Thu, 12 May 2022 21:41:22 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.37.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E2C7416156; Thu, 12 May 2022 21:41:05 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <20220504014440.3697851-20-keescook@chromium.org> References: <20220504014440.3697851-20-keescook@chromium.org> <20220504014440.3697851-1-keescook@chromium.org> To: Kees Cook Subject: Re: [PATCH 19/32] afs: Use mem_to_flex_dup() with struct afs_acl MIME-Version: 1.0 Date: Thu, 12 May 2022 22:41:05 +0100 Message-ID: <898803.1652391665@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dhowells@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Mailman-Approved-At: Mon, 16 May 2022 10:03:51 +0200 Cc: Vincenzo Frascino , Christian Lamparter , Eli Cohen , "K. Y. Srinivasan" , Louis Peens , Wei Liu , Hulk Robot , James Morris , xen-devel@lists.xenproject.org, Guenter Roeck , Marcel Holtmann , Arend van Spriel , 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 , Johannes Berg , 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 =?utf-8?Q?S=C3=A1?= , 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 =?utf-8?Q?G=C3=B6ttsche?= , Franky Lin , Felipe Balbi , Keith Packard , "Martin K. Petersen" , Liam Girdwood , Stefan Richter , "David S. Miller" , Daniel Vetter , llvm@lists.linux.dev, Bjorn Andersson , David Howells , wcn36xx@lists.infradead.org, Eugeniu Rosca , 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, Johannes Berg X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Kees Cook 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