Article View: linux.kernel.netdev
Article #3293Re: [PATCH net v2 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall
From: Stanislav Fomichev
Date: Wed, 14 Oct 2026 16:33
Date: Wed, 14 Oct 2026 16:33
54 lines
11421 bytes
11421 bytes
On 10/12, Mina Almasry wrote: > When a bound net_device is unregistered while userspace still holds a > netlink or TCP socket reference on a devmem binding, > mp_dmabuf_devmem_uninstall() clears binding->dev to NULL so > netdev_nl_sock_priv_destroy() will not touch the unregistered > net_device, but leaves the dma_buf attachment mapped until > __net_devmem_dmabuf_binding_free() runs later on socket close. > > Because dma_buf_attach() does not take a reference on dma_dev, device > removal frees dma_dev while the attachment is still mapped. Closing the > netlink socket afterwards triggers a slab use-after-free in > dma_unmap_sg_attrs(): > > BUG: KASAN: slab-use-after-free in dma_unmap_sg_attrs+0x76/0x2b0 > Read of size 8 at addr ffff88810fae64b0 by task kworker/3:1/53 > Workqueue: events __net_devmem_dmabuf_binding_free > Call Trace: > dma_unmap_sg_attrs+0x76/0x2b0 > unmap_udmabuf+0x8e/0x100 > dma_buf_unmap_attachment+0x145/0x330 > dma_buf_unmap_attachment_unlocked+0x96/0x130 > __net_devmem_dmabuf_binding_free+0x156/0x2e0 > Freed by task 9: > kfree+0x1b8/0x550 > nsim_bus_dev_release+0xe/0x60 > device_release+0xcf/0x250 > > Add net_devmem_dmabuf_binding_unmap() serialized under binding->lock > and null out binding->sgt and binding->attachment after unmapping so > unmapping is idempotent across queue uninstall and deferred binding > destruction. Call it synchronously when the last bound RX queue is > uninstalled in mp_dmabuf_devmem_uninstall(), except when a leased > queue is unleased: the physical device is still registered and, if > restarting its queue failed, may still be using the binding. > > The same use-after-free happens when the netlink socket is closed > before the device is removed but RX tokens or the pending release work > keep the binding alive. Such bindings are no longer installed on any > queue and were already erased from net_devmem_dmabuf_bindings. Keep > bindings in net_devmem_dmabuf_bindings until they are freed, hide > unbound ones from TX lookups with an xarray mark, and on > NETDEV_UNREGISTER clear binding->dev of unbound RX bindings for the > device and unmap them, unless the device is a virtual device leasing [..] > queues, for the same reason as above. net_devmem_lock serializes that > walk with the final free. Can you explain net_devmem_lock a bit more? In net_devmem_dev_unregister, why can you not net_devmem_lookup_dmabuf and then rely on the binding->lock? The rest looks good, but the new lock seems a bit excessive?
Technical Details
Message-ID:
<as-uBvRisS7HxLHJ@devvm7509.cco0.facebook.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-346345-linux-kernel-netdev=dewy.ruReferences:
<20261012174300.2338784-1-almasrymina@google.com> <20261012174300.2338784-2-almasrymina@google.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-346345-linux-kernel-netdev=dewy.ru
From: sdf.kernel@gmail.com (Stanislav Fomichev)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 1/4] net: devmem: unmap dma_buf synchronously on
queue uninstall
Date: Wed, 14 Oct 2026 09:33:38 -0700
Organization: Usenet Network
Message-ID: <as-uBvRisS7HxLHJ@devvm7509.cco0.facebook.com>
References: <20261012174300.2338784-1-almasrymina@google.com>
<20261012174300.2338784-2-almasrymina@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Info: usenet.network;
logging-data="2336676"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:A/fe2TuogP8sp64/rt1eH6MNCms= sha256:Z5HVAHpznels3jeJpIEOLv89DdgpLedjPP4PyBcQRP4=
sha1:FbTXjNHE5NkFAiy/noHLo281cYI= sha256:NbBYpZkB+tmS4eAj1kY1jP/VtQAdpXzdV0i0nf12Bb8=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 9081D11016F; Wed, 14 Oct 2026 19:47:25 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: 0.352
X-Spam-Status: No, score=0.352 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=no autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id sbIHBWjbZP_h;
Wed, 14 Oct 2026 19:47:22 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-346345-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 4FFDD11016C; Wed, 14 Oct 2026 19:47:13 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sea.lore.kernel.org (Postfix) with ESMTP id 073913E8AA; Wed, 14 Oct 2026 16:34:02 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id EDA0F55D860;
Wed, 14 Oct 2026 16:34:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pd7irBGa"
X-Received: from mail-pz2-f6.google.com (mail-pz2-f6.google.com [74.125.228.6])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id B17C8551982
for <netdev@vger.kernel.org>; Wed, 14 Oct 2026 16:33:59 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.6
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1791995640; cv=none; b=IrQcgQGaolsfT8GTcK91FGRwzOJKQu5E6T8N3WErW17rtj9bh79MDguYgJbGpL6XQuJbgcd1rm7jI+EqRXiObsuSokcmSu1hZo2tJIcAbARe+U0D27lLk35ETeWnUpBwLYOtRAor5Wdgv03KwoLmq8pzLu750K4sFZFyM7dOXSs=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1791995640; c=relaxed/simple;
bh=03prvWYuPM9S8kmgrWoC3fCmFozkGleIo9XhNkVgCtI=;
h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
Content-Type:Content-Disposition:In-Reply-To; b=od1ODIx2Z8pVyFApgiwLAFDmdx5sXeTluMBhoVlEUyF8JB+CfFp6EuG8cfq3QA/xeIFdZxp9KeBRyEDFkZnboEGMhVJiPQBHgqYo6i8g0/o1WY5OjjI7f8SFxy3HH1F9SqLSwQ69Y5zToU+U1fzGAvY3xMysVq36x6INOWs/KuQ=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Pd7irBGa; arc=none smtp.client-ip=74.125.228.6
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pz2-f6.google.com with SMTP id 41be03b00d2f7-cc790c60953so252207a12.1
for <netdev@vger.kernel.org>; Wed, 14 Oct 2026 09:33:59 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1791995639; x=1792600439; darn=vger.kernel.org;
h=in-reply-to:content-disposition:content-type:mime-version
:references:message-id:subject:cc:to:from:date:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=Gzw9aMKz/xODwzz6jPerfVV+ZDaTeiwtt+GIjli64uI=;
b=Pd7irBGaIfGk47A4W8byWcdXxiyBIqvKEbA9YhOh3SRQ6mJyIKIRRLuIPMYQAvnKMs
TiiQbQe1X9LW8PMlgREmTed2G73VpjPu9b/hQC6M7174NlPobQQvYC7JbWww84NvkGVc
jaPpkkunMPeYYbs7LRpYE1NB3orJeiitk5w+ztYeo5vRK1StrQIIlrqN8LPbbwn/q7pl
LyTa9PdacwnhwmfVzvAYeCHjMCxA/kI1BexjubiZ4KYMJIByLay2i2hNOuiNpYiGNnZr
oredyfHyKPao1I1MMDdfl/UgbblGTGEjrFSK49edHqKhn/nAtTq070F5HAFN7V6SOwU9
2M8g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1791995639; x=1792600439;
h=in-reply-to:content-disposition:content-type:mime-version
:references:message-id:subject:cc:to:from:date:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=Gzw9aMKz/xODwzz6jPerfVV+ZDaTeiwtt+GIjli64uI=;
b=auvlHfK1//JPnQUpxy9WkTdGSmpVsbcHcAx3CkUDnNMOFBQOTM/soZ0ZGHFn1sA8RR
Fnzfpv8wttIsk/RzQ75BAdVbqs6ZPa80HekzwXWpepl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3a.15.1791995639007;
Wed, 14 Oct 2026 09:33:59 -0700 (PDT)
X-Received: from localhost ([2a03:2880:2ff:59::])
by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-89d80511d47sm1291926b3a.54.2026.10.14.09.33.58
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 14 Oct 2026 09:33:58 -0700 (PDT)
X-Cc: Jakub Kicinski <kuba@kernel.org>, David Wei <dw@davidwei.uk>,
Pavel Begunkov <asml.silence@gmail.com>, Taehee Yoo <ap420073@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>, Paolo Abeni <pabeni@redhat.com>,
Kaiyuan Zhang <kaiyuanz@google.com>, Bobby Eshleman <bobbyeshleman@meta.com>, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>,
Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
Sumit Semwal <sumit.semwal@linaro.org>, Christian Kรถnig <christian.koenig@amd.com>,
Nikolay Aleksandrov <razor@blackwall.org>, Daniel Borkmann <daniel@iogearbox.net>,
Tariq Toukan <tariqt@nvidia.com>, Kaifeng Wang <kaifengw@google.com>
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-In-Reply-To: <20261012174300.2338784-2-almasrymina@google.com>