From patchwork Sun Oct 1 21:08:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 147160 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1055252vqb; Sun, 1 Oct 2023 14:09:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/LOA8X1ZZ7SR4sGgRFgcvpc+uIoglxH5qF0JlMvYPq18ozI9UkucUZtlok9K2UKyHIiYH X-Received: by 2002:a05:6870:1cc:b0:1c3:91b9:e1e7 with SMTP id n12-20020a05687001cc00b001c391b9e1e7mr13395308oad.21.1696194551398; Sun, 01 Oct 2023 14:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696194551; cv=none; d=google.com; s=arc-20160816; b=eg6jWXj976n3SB6bgUDtB2GRx33dxwKZCmYdGrdmEGITimTThHKEYWD1SpIaku62C4 PJ/pDbbfcFurFun9ONpzcixN6HzMTHFpP3Rx2QFN0lMJLdJ/8M19GCff86Dd4G82W/T1 XRgGpKfuQQuGcSFX/pt8HH8PXyHHfza/qwIR1HPSTBV6sUdkbohCGpToZb97RfSBfp/s TPFzqLFmc8hcGzmxZBJpYXJ+iIcziMHUBBKdI8qKmuSFnVyRy1st/e8nudKG7edAyDCL kI6VNuTf6QTa8goiFj20Dq7Y08H2YfV99tAXEsagqmQFzIADRFjDWONa9vbfPZoF2uTt E5hQ== 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: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 i7-20020a636d07000000b0057745b2d018si22849497pgc.390.2023.10.01.14.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 14:09:11 -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=IkTJexmQ; 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 A411D801B3F5; Sun, 1 Oct 2023 14:09:10 -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 S235308AbjJAVJK (ORCPT + 18 others); Sun, 1 Oct 2023 17:09:10 -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-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 (howler.vger.email [0.0.0.0]); Sun, 01 Oct 2023 14:09:10 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778588898114794323 X-GMAIL-MSGID: 1778588898114794323 `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 Reviewed-by: Logan Gunthorpe --- 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)