From patchwork Wed Aug 21 07:18:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13770948 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 3B011C52D7C for ; Wed, 21 Aug 2024 07:24:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kqXkRiyUxqSbliwQmHVEASu4D/RYGtBd8mGoyCxVF1o=; b=nXUjBmbs2073CYztfdOTjgOfY0 edylJwWWTAzWbH01uxqthUsURKeCRyKdMTCsa8SOFfJqfo1PU3LuVrOGXMs3JYLOcytEUtOMdYbqj l2zxKuWD7gczMNKu6r3UOUHShfw97bzLfrUyixzGS+7/KDUh8cXawTkZjzGxVGV9a2pbg4Arw3245 Oona4+OBe9xJV166OIVQ7f7DuN59QJBCK3PP+VdhzCTiXF04lYsUaGHbfhV4ergqBFrY3H0UUOTuw ZC5M58MKZCi7ca1b84tlaPkruz2ioaGouZDsQq5X9R5ULd03xkZxKWotFjJAWZrYpO78ni+80UR9k jDx7pneg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgfi2-00000007teo-3Ix2; Wed, 21 Aug 2024 07:24:46 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgfd6-00000007rn9-0vMr for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 07:19:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724224779; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kqXkRiyUxqSbliwQmHVEASu4D/RYGtBd8mGoyCxVF1o=; b=S2iV7tQpdQ/kn88sx1goxDRsivALqU30KDjo9/8eJhGciJ5iHQvqutWim4UWYmTxRyoUwe No2L9bCo32iFI5MLgW4Ft7xQT612qvYRv5VudDbjv7XQk9XFHt88m6nVaY3+F/xdwx68Uf rDfdcsayJ0Zjqm7H3eKfM7a3+EU6+5E= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-kSmjO5E8MaC--GOfRyqFTA-1; Wed, 21 Aug 2024 03:19:37 -0400 X-MC-Unique: kSmjO5E8MaC--GOfRyqFTA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7a1e9a383d1so613102885a.3 for ; Wed, 21 Aug 2024 00:19:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724224777; x=1724829577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kqXkRiyUxqSbliwQmHVEASu4D/RYGtBd8mGoyCxVF1o=; b=Oska7J6IhyqQOxdLkml9iFjWrEKz1ysny3MQYD8ncWXw4YcG6/5NsIqb1Auer6jwx5 daEpeBzK7+EMs7G4PWpC/Cj3EcSL1RC9dbw8CuF4/5JJfI3MZfJ3qq/ob++lyUVjKLD5 BK6QX66u1T76silMkOHt1hvHzL4feG18sYa3scmI2udE1hhbQNfnLfzlHXiDMa8YYtN5 2WX+kF/u6381lc4swwzoZD9m6vwTXuxIEgq/5lc7w9uoaWYJgqE0SxoZQQhrW40WAjVN SvaP3yfWx4ZEyR9ZSpj+TQIfLx0A0ZS4vdYaCKmhA9ojUsydrK/gSXhCe/zHWpD8S1ei FcKQ== X-Forwarded-Encrypted: i=1; AJvYcCX5+IwRBj48BNdBvS27S3BKH4W333Bv01E/XSU6uwlR8r4nKwHWU+HI+ZgkLDzfTkzlZ+n6jxbN4C2eGkzaGmTc@lists.infradead.org X-Gm-Message-State: AOJu0Yz1a524ia7jqA/yNHL9LcUK4D4Dg2ssx9ArjD3lg0I8Q4TQ+ciJ UWeD2+xXiP3z1OpsoaAsDqxzU/bxh9o4dOmrik696VfTb6BNjox25cg9j3sHmdm09aC4y/OeKZC caJ174/bsE1z/GTxyDtqVh4SA1Hs00oKvtPlNIDOnAgY62zfuOGw2kCrAVjiwEEDIrfS+D3/g X-Received: by 2002:a05:620a:4723:b0:795:5672:9298 with SMTP id af79cd13be357-7a674057cddmr157583485a.41.1724224776883; Wed, 21 Aug 2024 00:19:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzvsJUVRLWmc58Q7QaiuvVDQhxagsdXHOmahNlcC4bwy6acZdi9NrIfC29BkE+CkLUyoCrrg== X-Received: by 2002:a05:620a:4723:b0:795:5672:9298 with SMTP id af79cd13be357-7a674057cddmr157580485a.41.1724224776363; Wed, 21 Aug 2024 00:19:36 -0700 (PDT) Received: from eisenberg.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a4ff013ef2sm596207885a.11.2024.08.21.00.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 00:19:36 -0700 (PDT) From: Philipp Stanner To: Jonathan Corbet , Jens Axboe , Wu Hao , Tom Rix , Moritz Fischer , Xu Yilun , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Bjorn Helgaas , Alvaro Karsz , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , Richard Cochran , Mark Brown , David Lechner , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Philipp Stanner , Damien Le Moal , Hannes Reinecke , Keith Busch Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fpga@vger.kernel.org, linux-gpio@vger.kernel.org, netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, virtualization@lists.linux.dev, stable@vger.kernel.org, Christophe JAILLET Subject: [PATCH v2 7/9] vdpa: solidrun: Fix potential UB bug with devres Date: Wed, 21 Aug 2024 09:18:40 +0200 Message-ID: <20240821071842.8591-9-pstanner@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240821071842.8591-2-pstanner@redhat.com> References: <20240821071842.8591-2-pstanner@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_001940_356843_B9732CE4 X-CRM114-Status: GOOD ( 15.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In psnet_open_pf_bar() a string later passed to pcim_iomap_regions() is placed on the stack. Neither pcim_iomap_regions() nor the functions it calls copy that string. Should the string later ever be used, this, consequently, causes undefined behavior since the stack frame will by then have disappeared. Fix the bug by allocating the string on the heap through devm_kasprintf(). Cc: stable@vger.kernel.org # v6.3 Fixes: 51a8f9d7f587 ("virtio: vdpa: new SolidNET DPU driver.") Reported-by: Christophe JAILLET Closes: https://lore.kernel.org/all/74e9109a-ac59-49e2-9b1d-d825c9c9f891@wanadoo.fr/ Suggested-by: Andy Shevchenko Signed-off-by: Philipp Stanner --- drivers/vdpa/solidrun/snet_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/solidrun/snet_main.c b/drivers/vdpa/solidrun/snet_main.c index 99428a04068d..4d42a05d70fc 100644 --- a/drivers/vdpa/solidrun/snet_main.c +++ b/drivers/vdpa/solidrun/snet_main.c @@ -555,7 +555,7 @@ static const struct vdpa_config_ops snet_config_ops = { static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet) { - char name[50]; + char *name; int ret, i, mask = 0; /* We don't know which BAR will be used to communicate.. * We will map every bar with len > 0. @@ -573,7 +573,10 @@ static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet) return -ENODEV; } - snprintf(name, sizeof(name), "psnet[%s]-bars", pci_name(pdev)); + name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "psnet[%s]-bars", pci_name(pdev)); + if (!name) + return -ENOMEM; + ret = pcim_iomap_regions(pdev, mask, name); if (ret) { SNET_ERR(pdev, "Failed to request and map PCI BARs\n");