From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF53C17A590 for ; Wed, 21 Aug 2024 12:26:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724243168; cv=none; b=qGqRou7WaVGLYwpeGSxPFLc0nsMmgCVp8l/MPKkYYL9yiSiNVc+DeTiiV5sPDdVWKesrAktfTDqNlCNpQbBfTik8Sk6m/BC9TfEFveRIbdDMSLxFGk1Aewmy8HYsEOzYcKTn8NqRanfJKQd2uGkCr6nO/3s//uGjBn3oiEwdu18= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724243168; c=relaxed/simple; bh=uuRCWDxDb6ZlmmrDflEcqKb34QjG6BdOf9n0HKg89DY=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=NLKyf/hfTi4g02zPJWDtuR5vkXw2AEh1RV03aVHhffYnlvHoDvoN6fzrSSyfi00hpERtzD2xICDGjlwl/ZgrV/FYBCkBbMMfJ4dcDf68pQsmokYPL467fp7COR5+Usd39Y5sh3Y7OVpy7PwDpEy/nLgZK57eL6cYFGqar7WSCQA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=jCwK6FmL; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jCwK6FmL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724243165; 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=F+8Zd9p9xEaFFxq9bSwT6CVTjqvDBBcELEezra/NBmQ=; b=jCwK6FmLFbchFIo6pYAoaDlK2NYeGNMLwRyRjGg9Bx4wUjfRaR88vmH6sRH2B/pTkxKPLc InCKTW5ZTfcy2mXpqgR2oX3QpxPVhcA6i+VQpC3bI84zPOL3/IoAn6infnrCMJaoFvDukn wpzrhu4BZg8xhJP2s1WjU0CH0XlM2C4= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-31-T_kP1psTNDqRc3oTdd8JwQ-1; Wed, 21 Aug 2024 08:26:04 -0400 X-MC-Unique: T_kP1psTNDqRc3oTdd8JwQ-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6bb84f0652eso68098406d6.0 for ; Wed, 21 Aug 2024 05:26:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724243164; x=1724847964; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=F+8Zd9p9xEaFFxq9bSwT6CVTjqvDBBcELEezra/NBmQ=; b=ac0C85bP9ar7GSpMfSMY2ZckgmXoQHGR1/zBu9vAVVkl3Kp/Kv9JI/96Ti5Oun+84E lG1IVqtDEmj54EhZzy89UBuXs203rx1ELf4mH00+z71kiPvmYL9lxm+XupEkpUbkLDjQ sVYdnae1mUXUDg9Z0XR99VEerZ5hHXHRtkmigQj2/bxnPmng/hIVpHUvoPgRzjoAbO58 6HbL9DHkhp5Z+Nq36UGFfgKs7paWEpaj/88pagejHraBl4RgwbaEr0/EJXv9/VqS59QQ OGItrO3HVoWqfTpRJzUCHpnw3Wx8VPYJkkRgxrdALS2Ejhbp8Evjxuyf9Svk2flFIXP5 QMbg== X-Forwarded-Encrypted: i=1; AJvYcCVSxWXmfCYURYafGG7DJnjX9bHBCCHTX8kDYVFmGDdASgQJDwnvOVP5dRbMfuRP31ZzlmIpSpaeCxbo@vger.kernel.org X-Gm-Message-State: AOJu0YxzH7szE6Cy/6PVWz1LTaZrIhwl6yj5zkCurWbQ2m2Q2jopqJ4S 0gQMsXcDU2LpgVQ21abllog0Q7IzNUrsZ2l43HPIPxG2/A1ihlhmG/mlocWz7xkVRVOb+mL6W0r Xy7H09GeD1BUDPh442aefQoguWut4ZGnw8RPYU2qoH1mx+Qrk1AqwcnRvDeI= X-Received: by 2002:a05:6214:4881:b0:6bf:a721:9945 with SMTP id 6a1803df08f44-6c1567fabf5mr30554866d6.24.1724243163964; Wed, 21 Aug 2024 05:26:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0sBOMGGLa2XcF/yRLMaOTYNrH07fkAWiC1e2c/uh8oASqBZoK+O1goCyf57ZnaX9oaF0YiA== X-Received: by 2002:a05:6214:4881:b0:6bf:a721:9945 with SMTP id 6a1803df08f44-6c1567fabf5mr30554416d6.24.1724243163535; Wed, 21 Aug 2024 05:26:03 -0700 (PDT) Received: from dhcp-64-164.muc.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bf6ff0dcdasm60220946d6.140.2024.08.21.05.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:26:03 -0700 (PDT) Message-ID: Subject: Re: [PATCH v2 7/9] vdpa: solidrun: Fix potential UB bug with devres From: Philipp Stanner To: "Michael S. Tsirkin" Cc: 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 , Jason Wang , Xuan Zhuo , Eugenio =?ISO-8859-1?Q?P=E9rez?= , Richard Cochran , Mark Brown , David Lechner , Uwe =?ISO-8859-1?Q?Kleine-K=F6nig?= , Damien Le Moal , Hannes Reinecke , Keith Busch , 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 Date: Wed, 21 Aug 2024 14:25:57 +0200 In-Reply-To: <20240821081213-mutt-send-email-mst@kernel.org> References: <20240821071842.8591-2-pstanner@redhat.com> <20240821071842.8591-9-pstanner@redhat.com> <20240821081213-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.4 (3.52.4-1.fc40) Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Wed, 2024-08-21 at 08:12 -0400, Michael S. Tsirkin wrote: > On Wed, Aug 21, 2024 at 09:18:40AM +0200, Philipp Stanner wrote: > > 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. > >=20 > > Should the string later ever be used, this, consequently, causes > > undefined behavior since the stack frame will by then have > > disappeared. > >=20 > > Fix the bug by allocating the string on the heap through > > devm_kasprintf(). > >=20 > > 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@wanado= o.fr/ > > Suggested-by: Andy Shevchenko > > Signed-off-by: Philipp Stanner >=20 > I don't get why is this a part of a cleanup series - > looks like an unrelated bugfix? It was discovered in the discussion of v1 of this series. It indeed is an unrelated bugfix and could be merged separately. But my patch #8 depends on it. So it would be convenient to merge it into mainline through this series, and have stable just pick patch #7. Or should it be done differently, in your opinion? P. >=20 >=20 > > --- > > =C2=A0drivers/vdpa/solidrun/snet_main.c | 7 +++++-- > > =C2=A01 file changed, 5 insertions(+), 2 deletions(-) > >=20 > > 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 =3D { > > =C2=A0 > > =C2=A0static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet > > *psnet) > > =C2=A0{ > > - char name[50]; > > + char *name; > > =C2=A0 int ret, i, mask =3D 0; > > =C2=A0 /* We don't know which BAR will be used to communicate.. > > =C2=A0 * 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) > > =C2=A0 return -ENODEV; > > =C2=A0 } > > =C2=A0 > > - snprintf(name, sizeof(name), "psnet[%s]-bars", > > pci_name(pdev)); > > + name =3D devm_kasprintf(&pdev->dev, GFP_KERNEL, "psnet[%s]- > > bars", pci_name(pdev)); > > + if (!name) > > + return -ENOMEM; > > + > > =C2=A0 ret =3D pcim_iomap_regions(pdev, mask, name); > > =C2=A0 if (ret) { > > =C2=A0 SNET_ERR(pdev, "Failed to request and map PCI > > BARs\n"); > > --=20 > > 2.46.0 >=20