Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp980887rdb; Sun, 1 Oct 2023 14:09:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHyPRdh4KvQKnlK7AJ2FMZOSycKUghjjmyN6kK5ixnFavOAPyPr0nzG+n9gh8H79hPwYRv X-Received: by 2002:a05:6a20:4290:b0:14b:3681:567e with SMTP id o16-20020a056a20429000b0014b3681567emr9827291pzj.29.1696194552749; Sun, 01 Oct 2023 14:09:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696194552; cv=none; d=google.com; s=arc-20160816; b=FGJ7PIqCFG92NL+4wAugGqn7RUBw3Q3IzlgSVsaCK2HE5ivxW08AEXPnUE4s1feN4/ od4hHx5jTn1MnLIGDRMVG/NML2tgf04o5i/mqsn0cyJqtgg4JB0sFIL3oaxSR69mZ2zr nooxHPk389/EC1RLKYuc2Vo2bSYQaemg0NIIacnc7M4fAn8jvrel6VkshiGIGa6urdeE KB+JteYoeSkfcWpcDKdUYOPTg9aG2J3zdpdqoEo4c3f6I/12za20z6DlqPbgKEjulSg2 +AorTgRgiO7v5sLqvAe8bPaI2tIsVz67ooPERIeocUSjdAf3SpWrKfpZEevLUPRyGRP0 15eg== 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=SEF3+T7LLGY0ZyZDXBOUDpCtVB7tIpQqW28cuWU/ZY4=; fh=w/LZzD1n/GJRsfuejvz5M7M+qCJ/KfmrI4/Yak1ED+g=; b=mfxKkFVS4R+d003ODm26I0EebTcT6YNsFXWXq10R3wf5p0Q/fynco/T8jF6CEemXkm TVTgVVwshrOj8fo0zJw+MHxy/DQ2juGIEAqH3bDdyDZOFbs02qrldIBR+SOWXxF1O1vx L1DYU5Ap5Ndoe3ydeK7RFn5gLY+BzEu3lkOc9Lu7bMA+6KHAayUFIJi0Ekr01pMC1WKB VNUQ++R/mUci0UDfX482foB5Fm+OzpRIYDytxWF9PYXjqCYqZSH3TdEHq1MlrKQZNAPp vC+LIsv/Z+esLXv7l+NvsNMu6dGSz3vUNjieFFSRky1wkfrrBawvcrVYgXR4sKtEPy18 3fZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IkTJexmQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id j11-20020a170902da8b00b001c62139b164si18632467plx.38.2023.10.01.14.09.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 14:09:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IkTJexmQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 031E080408CC; Sun, 1 Oct 2023 14:09:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235299AbjJAVJJ (ORCPT + 99 others); Sun, 1 Oct 2023 17:09:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235161AbjJAVJJ (ORCPT ); Sun, 1 Oct 2023 17:09:09 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B54CBF; Sun, 1 Oct 2023 14:09:06 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9F79C433C7; Sun, 1 Oct 2023 21:09:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696194546; bh=KlpsTUbvJ/T3JQMeSxp6/dgvFP7eP+U9AV1bcVV6PP0=; h=Date:From:To:Cc:Subject:From; b=IkTJexmQrS6lFMoEvE68sJw8EwkmmMhbHx0qcxU8M9m3i6FnVbp5hSSh3YNxhwG7s VJ0NroEzoyK+n+dKuNwwvnruRe0hioND27AReoy80kzCUM9Tqwmop46j1H1G5qUzb2 mWiTPlTEgfq6Tz8ZqRnNrxJKmDbMs4PexTD3XY3aJ3Zaig4Rqa3JHDpS7pRuvvpMBC AG/T3jo+VqFuPR/Tm9bwNeGH+jh3a0b20qVGjfDdDg8i5UmfJIWLB9QPpXJW8rO0Gl Qc7ODBciOQHZz+ziLfmv91qrXKdXgjBrloxAGWo/H8HWFnFM9t0vmWEny/zXiCw6zz oHGNIqbElVGJA== Date: Sun, 1 Oct 2023 23:08:59 +0200 From: "Gustavo A. R. Silva" To: Bjorn Helgaas , Logan Gunthorpe Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] PCI/P2PDMA: Fix undefined behavior bug in struct pci_p2pdma_pagemap Message-ID: 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: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 01 Oct 2023 14:09:12 -0700 (PDT) `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`. 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. Fixes: 0afea3814358 ("PCI/P2PDMA: Add provider's pci_dev to pci_p2pdma_pagemap struct") Fixes: a6e6fe6549f6 ("PCI/P2PDMA: Introduce private pagemap structure") Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva --- 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