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 A00C117624C 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-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-487-Z72d8CB2PsKCagxnCq-c1A-1; Wed, 21 Aug 2024 08:26:04 -0400 X-MC-Unique: Z72d8CB2PsKCagxnCq-c1A-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6bf788e4692so61609836d6.2 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=gtqYboP9mDlQg7YDCGAXh7RL06zT2BC3L7VvNbGTvqkuynrid3RwSt96WW0KF31F0k CnU65Oe9oe511PvdLUNWWaEads/9iRvaOiRNmSujYnF6pO0rpzKtnhbrtgPluum8crny plUvKOm89febkdqexD5750coIrvF/xy1ip74e0OKPTZvDFq94vJFZlEheqrGrVaRwPvu uSyp+BS/e9dW9zIRmE5UwjCwvESHiPRptiSYTXiEVkiXle/XiQYvgESKtbL+ByR9N9II AED9aslVhWkYFwVPdquKnTEDRqZ2sWnySLvLQGmrUqbK9duukF4XU/hbLuYJfDY1uz/a Q3TA== X-Forwarded-Encrypted: i=1; AJvYcCUXeBQsWfa4gv18rcdH0tiBNN8catKgI3aY/h1R0Or5185smmU7YPPOPlgiVp1G+DMN9chYHCU0FEMclYo=@vger.kernel.org X-Gm-Message-State: AOJu0YzC/ZddMTiI/5C8MllR0p/QLr/Ni2Fn/bUiUMr1gRVjoNgXrGno Y8NDz09pvLbL29d+DIKHUVulImsOH9IcW4DfUt61v2snmO5v+omm9YFHTsKOol/NxJbwajLD7Bz fEwnD7hlde5nfxaipQxTk+9bjrUTl3SR6ZortCHzXQ1nFu/IyMJMsSxadfbUGUw== X-Received: by 2002:a05:6214:4881:b0:6bf:a721:9945 with SMTP id 6a1803df08f44-6c1567fabf5mr30554976d6.24.1724243163966; 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-kernel@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