[v2,next] PCI/P2PDMA: Fix potential undefined behavior bug in struct pci_p2pdma_pagemap
Message ID | ZRsUL/hATNruwtla@work |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1680587vqb; Mon, 2 Oct 2023 13:44:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHY08XEBX+7IoaY3k+ZnVMY6uzhD5CP2y9RalK/0rn6XVEdtuq06cLAGAD07Npc0dnge6YQ X-Received: by 2002:a25:dc06:0:b0:d12:ccc7:2392 with SMTP id y6-20020a25dc06000000b00d12ccc72392mr9129815ybe.4.1696279473739; Mon, 02 Oct 2023 13:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696279473; cv=none; d=google.com; s=arc-20160816; b=fagjk0EZvBoQZFIZT/ald+nR9kZMbb+5yg1nQB9omFtOhDnj4s7IZdid+C37eihLNt IDwBPSn58VuEVJjsf7hGtNGe32lJp8YhScm0RudRw4mO+LETvpe/K4QxvUQA0aqy1vlZ RT4wuoD4WpZtYslVJGlOZIMNglfAwrm9zcJjONzrBg2h+4q3OKHxcrWqJPmx00lbqjN8 kjlZq/iet7w6sRvwUBaZs5Et/IjEZEhPZb37YgRYJBhUl0UcN1ALOP7gdXS9a5V9njXi VsDAMejOTnioNYJUt1PixOpscM6sQSWG+f7VlGW0Js9FkgDxqVdVod5ttCN3haM0XTF3 9ZnQ== 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=C05RVlYA4ZdAVgaKXiYosGLZYVQ6zHdktJEDX3CQUdE=; fh=w/LZzD1n/GJRsfuejvz5M7M+qCJ/KfmrI4/Yak1ED+g=; b=Ovd7vNYF0hm5GQldfpFfqXGLieCK2CmpDzxjoLitDq/2XQIlAB5j9oU+id3wKX8eVO LRu3CiTUk8j0+MsDI2Zn9+O8e+ncX5s8JRKU8nHjE91uEONCOIiSmcgryl8cG0ATB472 14rNqp5k7ZEk5oFz/xIpXWsLV8qW4UtoeSD5CgOGoF6Vr6WnyA7pro3o3Fv9t1WjGdzN dSBhS65/1Y+tGGt9VZRa29KTa2Kr6RrQcrs5squBQ/xpbXJsViVo3G3fIge7uNyezWDm 67hKMKrC7AwKTx0DY0OuF5tZjFOsllUyV4IQ/sNaetgvETZkQiMRUUJhv4TlwxYo4jyD /kGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QF68u+gM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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. [23.128.96.34]) by mx.google.com with ESMTPS id s132-20020a63778a000000b0057ab7f46d3dsi7137996pgc.108.2023.10.02.13.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 13:44:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QF68u+gM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 56558801B994; Mon, 2 Oct 2023 12:04:27 -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 S238566AbjJBTEZ (ORCPT <rfc822;pusanteemu@gmail.com> + 18 others); Mon, 2 Oct 2023 15:04:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238554AbjJBTEX (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 2 Oct 2023 15:04:23 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E540AC; Mon, 2 Oct 2023 12:04:21 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65B99C433C9; Mon, 2 Oct 2023 19:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696273460; bh=VEsg6fqTYDhVGFa0jJFgmDsU8/UVfT6A/kgPl1u/lKg=; h=Date:From:To:Cc:Subject:From; b=QF68u+gMvrufyxKFrnkBWEMr0/SzIT2kIX44C9Mo0AZB2WHDANcLRhPD3Ge7Whh81 s/argLonEHJVRZu4OnmpvlpQMlad4AHnzvOGTN9YsMF9UAQdYNF1Aa69gyZJ5aGFpA kQ+/DP/j/lSjkIrY2i34ifMUrkMrSxISkfiB1V9dDo7iPzH0mwlKuRn6kYhcf0Yk67 LZWolKmOQbIvzX/wL2//a9Fbe508gumHrFqp1kcf8av3dMjgBLSzpLeWYrtzqdZVp/ a5CNv3ruL7MoM55v+p3K316nThNK2MT2WWTxLuttyS1j0gWsM+tWksFg4asxAdLW6X nbXHL5DhWNykA== Date: Mon, 2 Oct 2023 21:04:15 +0200 From: "Gustavo A. R. Silva" <gustavoars@kernel.org> To: Bjorn Helgaas <bhelgaas@google.com>, Logan Gunthorpe <logang@deltatee.com> Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" <gustavoars@kernel.org>, linux-hardening@vger.kernel.org Subject: [PATCH v2][next] PCI/P2PDMA: Fix potential undefined behavior bug in struct pci_p2pdma_pagemap Message-ID: <ZRsUL/hATNruwtla@work> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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]); Mon, 02 Oct 2023 12:04:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778677945893111241 X-GMAIL-MSGID: 1778677945893111241 |
Series |
[v2,next] PCI/P2PDMA: Fix potential undefined behavior bug in struct pci_p2pdma_pagemap
|
|
Commit Message
Gustavo A. R. Silva
Oct. 2, 2023, 7:04 p.m. UTC
`struct dev_pagemap` 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 `pgmap` in `struct pci_p2pdma_pagemap`, when `nr_range > 1`. This is currently not the case (notice that `nr_range` is hardcoded to `1`), however as commit b7b3c01b1915 ("mm/memremap_pages: support multiple ranges per invocation") mentions in the subject line, this code can `support multiple ranges per invocation`. So, we'd better prevent any problems that may arise in the future. Fix this by placing the declaration of object `pgmap` at the end of `struct pci_p2pdma_pagemap`. -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally. Reviewed-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> --- Changes in v2: - Remove `Fixes:` tags. (Logan Gunthorpe) - Update changelog text. Make it clear that `nr_range` is hardcoded to `1` (Logan Gunthorpe) - Update subject. - Add Logan's RB. v1: Link: https://lore.kernel.org/linux-hardening/ZRnf6wVOu0IJQ2Ok@work/ drivers/pci/p2pdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Mon, Oct 02, 2023 at 09:04:15PM +0200, Gustavo A. R. Silva wrote: > `struct dev_pagemap` 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 `pgmap` in `struct > pci_p2pdma_pagemap`, when `nr_range > 1`. This is currently not the > case (notice that `nr_range` is hardcoded to `1`), however as commit > b7b3c01b1915 ("mm/memremap_pages: support multiple ranges per invocation") > mentions in the subject line, this code can `support multiple > ranges per invocation`. So, we'd better prevent any problems that may > arise in the future. > > Fix this by placing the declaration of object `pgmap` at the end of > `struct pci_p2pdma_pagemap`. > > -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting > ready to enable it globally. > > Reviewed-by: Logan Gunthorpe <logang@deltatee.com> > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Applied to pci/p2pdma for v6.7. Since it's not a current problem, I assume there's no reason to apply it for v6.6 (or tag it for stable); let me know if otherwise. > --- > Changes in v2: > - Remove `Fixes:` tags. (Logan Gunthorpe) > - Update changelog text. Make it clear that `nr_range` is hardcoded to `1` > (Logan Gunthorpe) > - Update subject. > - Add Logan's RB. > > v1: > Link: https://lore.kernel.org/linux-hardening/ZRnf6wVOu0IJQ2Ok@work/ > > drivers/pci/p2pdma.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c > index fa7370f9561a..ab34d3d36a64 100644 > --- a/drivers/pci/p2pdma.c > +++ b/drivers/pci/p2pdma.c > @@ -28,9 +28,9 @@ struct pci_p2pdma { > }; > > struct pci_p2pdma_pagemap { > - struct dev_pagemap pgmap; > struct pci_dev *provider; > u64 bus_offset; > + struct dev_pagemap pgmap; > }; > > static struct pci_p2pdma_pagemap *to_p2p_pgmap(struct dev_pagemap *pgmap) > -- > 2.34.1 >
diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index fa7370f9561a..ab34d3d36a64 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -28,9 +28,9 @@ struct pci_p2pdma { }; struct pci_p2pdma_pagemap { - struct dev_pagemap pgmap; struct pci_dev *provider; u64 bus_offset; + struct dev_pagemap pgmap; }; static struct pci_p2pdma_pagemap *to_p2p_pgmap(struct dev_pagemap *pgmap)