Message ID | ZRb0WiViajjqcyKT@work |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp4147063vqu; Fri, 29 Sep 2023 09:11:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuFl5yLxKXWnlOOKHRzMSG6rfw0Qs4abAqvWarXI4N6DnNRZbJWdjtWmOktMMJHT+J5R1a X-Received: by 2002:a05:6a00:847:b0:692:7527:c2d0 with SMTP id q7-20020a056a00084700b006927527c2d0mr4973075pfk.32.1696003884359; Fri, 29 Sep 2023 09:11:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696003884; cv=none; d=google.com; s=arc-20160816; b=sTJeIxevtpqDcs7/frtM8gcL20jT3hoxwiyVvbgkl4NutcE+CA7aiqPI2Uh3pP2Mp/ Q71z5y3ah6YWLSJszh6qeI7+9G7WrUcg8qH3O2+5RpfbSAJSlYLmo5pG30XawJFbZToc Z7+n4BC4K9ffnz/T1+t0UZ32ggvVaUtWHr+xHmca7YhHJ5rLf+N99NPzAZAtmJT0taBj 33jR9XklmS2xcRx3U4uus9V522MCeWt12v1VcqkwJgTnRCbJvuTg9TXW9H2wIpG9JekR Ky9JQNnB5IipjsLI5kXFJyWz5hwjpTTakozSW4XU9ZCNVkiKDMsbeXeOnqZ8r9IPVRU/ Do9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=0ttJTwKN130+tmHo29VT2VrWZht6be55rIjfXfE96vA=; fh=mSzG5hg4bwmmmuflZ4+7bzKFkfPIridSyVHkXiuikO4=; b=j5XCRtqAtDgl7CJsWs3rxvzRHd5Gy4gF8MCR0Rx05xZEG594SVyPNfY/uJBdbhZvuc nFHus/2wp0wlZXBRsRddCXg1skYfeIQoR476HS0gOkPFgNq+hZQ+yW3zY5DXIhyguV8G jlRTeiQAJCQ0487c7WnEiHvJKRlfa74zGcrpcA33Z5NJOxj9az+215fUWVsknZhZ3sXx Nyv98lHqnnInNfDLUsrBBact+Cm/ZVBbg11ijtoXx/WY9UcIOyyTc6fIAIxbVxHaLdA9 iYb7iNeLGmynGO7Ll0feLq4u7U3gl5oHUQj04AtqA2dLQMzPnc7fajlIie3UGXR+TyL6 zwSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ji33FVLv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id eh11-20020a056a00808b00b0068ace3816d7si21199557pfb.387.2023.09.29.09.11.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 09:11:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ji33FVLv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 3F84385FEDAA; Fri, 29 Sep 2023 08:59:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233665AbjI2P7c (ORCPT <rfc822;pwkd43@gmail.com> + 20 others); Fri, 29 Sep 2023 11:59:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233141AbjI2P7b (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 29 Sep 2023 11:59:31 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8BBE139 for <linux-kernel@vger.kernel.org>; Fri, 29 Sep 2023 08:59:29 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF5B3C433C8; Fri, 29 Sep 2023 15:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696003169; bh=MnZquLPkDBkjKHQwlCsmfD9plASD37pKQYphc5bm4a0=; h=Date:From:To:Cc:Subject:From; b=Ji33FVLvtjef5TpdrXCXT+tOfwK7X6QqaDW/sSTW4uncDJ0ZD9QBIZRmOUQKsgWmN QAMCATmVFijx8Ajh0KRMVLs4/Ie2iez01r2ZQyzhpaJR+MveEuei8hv1I1+AA1xmW3 4PH/aAAdF0p2YDAtLRE8dOPiriMcOvZcelN0alOaurtwQY6DGn94/ko5B/BINekQ74 IfRn7eWnesujGiT4JQEJYxfMUmcCRe8TLku3hCbeiZvI/IFBpvXE7FdC6PNebn/cwN eOpJTyQLqnuKMSDxcxYEvvGb6KYot/hn7gOtIDSNOP8ZDBbsQUVchp6GoohIeN39cX QDXFd3aOUztUg== Date: Fri, 29 Sep 2023 17:59:22 +0200 From: "Gustavo A. R. Silva" <gustavoars@kernel.org> To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, Jussi Kivilinna <jussi.kivilinna@iki.fi> Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" <gustavoars@kernel.org>, linux-hardening@vger.kernel.org Subject: [PATCH][next] ALSA: 6fire: Fix undefined behavior bug in struct comm_runtime Message-ID: <ZRb0WiViajjqcyKT@work> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 29 Sep 2023 08:59:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778388968862934196 X-GMAIL-MSGID: 1778388968862934196 |
Series |
[next] ALSA: 6fire: Fix undefined behavior bug in struct comm_runtime
|
|
Commit Message
Gustavo A. R. Silva
Sept. 29, 2023, 3:59 p.m. UTC
`struct urb` is a flexible structure, which means that it contains a
flexible-array member at the bottom. This could potentially lead to an
overwrite of the objects following `receiver` in `struct comm_runtime`,
among them some function pointers.
Fix this by placing the declaration of object `receiver` at the end of
`struct comm_runtime`.
Fixes: ddb6b5a96437 ("ALSA: 6fire: fix DMA issues with URB transfer_buffer usage")
Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
sound/usb/6fire/comm.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, Sep 29, 2023 at 05:59:22PM +0200, Gustavo A. R. Silva wrote: > `struct urb` is a flexible structure, which means that it contains a > flexible-array member at the bottom. This could potentially lead to an > overwrite of the objects following `receiver` in `struct comm_runtime`, > among them some function pointers. > > Fix this by placing the declaration of object `receiver` at the end of > `struct comm_runtime`. > > Fixes: ddb6b5a96437 ("ALSA: 6fire: fix DMA issues with URB transfer_buffer usage") > Cc: stable@vger.kernel.org > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Should these mention -Wflex-array-member-not-at-end ? Reviewed-by: Kees Cook <keescook@chromium.org>
On 9/29/23 19:26, Kees Cook wrote: > On Fri, Sep 29, 2023 at 05:59:22PM +0200, Gustavo A. R. Silva wrote: >> `struct urb` is a flexible structure, which means that it contains a >> flexible-array member at the bottom. This could potentially lead to an >> overwrite of the objects following `receiver` in `struct comm_runtime`, >> among them some function pointers. >> >> Fix this by placing the declaration of object `receiver` at the end of >> `struct comm_runtime`. >> >> Fixes: ddb6b5a96437 ("ALSA: 6fire: fix DMA issues with URB transfer_buffer usage") >> Cc: stable@vger.kernel.org >> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > > Should these mention -Wflex-array-member-not-at-end ? Probably, yes. I wasn't sure about mentioning it because it's not been released yet. > > Reviewed-by: Kees Cook <keescook@chromium.org> > Thanks! -- Gustavo
On Fri, 29 Sep 2023 17:59:22 +0200, Gustavo A. R. Silva wrote: > > `struct urb` is a flexible structure, which means that it contains a > flexible-array member at the bottom. This could potentially lead to an > overwrite of the objects following `receiver` in `struct comm_runtime`, > among them some function pointers. > > Fix this by placing the declaration of object `receiver` at the end of > `struct comm_runtime`. > > Fixes: ddb6b5a96437 ("ALSA: 6fire: fix DMA issues with URB transfer_buffer usage") > Cc: stable@vger.kernel.org > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Sorry for the late reply, as I've been (still) off since the last week. Through a quick glance, I don't mind much to apply this, but I still wonder how this "fixes" anything. Does it silence compiler warnings or such? Certainly struct urb *may* have flex array, but in this case, it's clearly not used, so it's fixed-size. And, even if we shuffle the member to put to the last, it doesn't fix anything automagically alone. If a flex array were used, it still leads to memory corruption unless we implement the allocation properly. So I find the patch description is somehow misleading. thanks, Takashi > --- > sound/usb/6fire/comm.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/sound/usb/6fire/comm.h b/sound/usb/6fire/comm.h > index 2447d7ecf179..ee81572a4eec 100644 > --- a/sound/usb/6fire/comm.h > +++ b/sound/usb/6fire/comm.h > @@ -19,7 +19,6 @@ enum /* settings for comm */ > struct comm_runtime { > struct sfire_chip *chip; > > - struct urb receiver; > u8 *receiver_buffer; > > u8 serial; /* urb serial */ > @@ -30,6 +29,7 @@ struct comm_runtime { > int (*write8)(struct comm_runtime *rt, u8 request, u8 reg, u8 value); > int (*write16)(struct comm_runtime *rt, u8 request, u8 reg, > u8 vh, u8 vl); > + struct urb receiver; > }; > > int usb6fire_comm_init(struct sfire_chip *chip); > -- > 2.34.1 >
diff --git a/sound/usb/6fire/comm.h b/sound/usb/6fire/comm.h index 2447d7ecf179..ee81572a4eec 100644 --- a/sound/usb/6fire/comm.h +++ b/sound/usb/6fire/comm.h @@ -19,7 +19,6 @@ enum /* settings for comm */ struct comm_runtime { struct sfire_chip *chip; - struct urb receiver; u8 *receiver_buffer; u8 serial; /* urb serial */ @@ -30,6 +29,7 @@ struct comm_runtime { int (*write8)(struct comm_runtime *rt, u8 request, u8 reg, u8 value); int (*write16)(struct comm_runtime *rt, u8 request, u8 reg, u8 vh, u8 vl); + struct urb receiver; }; int usb6fire_comm_init(struct sfire_chip *chip);