Article View: linux.kernel.netdev
Article #2399Re: [PATCH net-next v8 6/8] hsr: Assign a socket for cloned skbs
From: Sebastian Andrzej Siewior
Date: Mon, 12 Oct 2026 15:33
Date: Mon, 12 Oct 2026 15:33
114 lines
11360 bytes
11360 bytes
On 2026-10-06 14:31:20 [+0000], netdev-bot+sashiko@kernel.org wrote:
> [Severity: Low]
> Could the commit message say that this only covers port-directed PTP
> frames?
>
> hsr_create_tagged_frame() only assigns the socket when
> frame->req_tx_port != HSR_PT_NONE. hsr_dev_xmit() only moves tx_port away
> from HSR_PT_NONE for ETH_P_1588 frames that carry the inline HSR header.
> The has_foreign_header path in hsr_forward_do() also needs a port.
>
> Other traffic that asks for TX timestamps still reaches the slaves as
> clones with skb->sk == NULL. One example is a UDP socket using
> SO_TIMESTAMPING over hsr0. For those clones, __skb_tstamp_tx() returns
> early:
…
UDP timestamping is not a thing here (in HSR).
> The restriction looks deliberate, since it avoids one timestamp per slave
> and double charging. The message, though, reads as if it applies to all
> cloned skbs.
>
> The message also leaves out the side effects of skb_set_owner_w(). The
> clone is now charged to the sender's sk_wmem_alloc, and its skb->hash and
> ooo_okay now come from the socket.
Right. None of this should have an impact that should be mentioned
explicitly. The primary motivation is the timestamp information which
requires the socket.
The accounting for sk_wmem_alloc happens, too. The original skb is freed
early.
> > diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
> > index 562802ddff003..46f9bd5039821 100644
> > --- a/net/hsr/hsr_forward.c
> > +++ b/net/hsr/hsr_forward.c
>
> [ ... ]
>
> > @@ -348,6 +349,9 @@ struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
> > if (!skb)
> > return NULL;
> >
> > + if (frame->req_tx_port != HSR_PT_NONE && frame->skb_std->sk)
> > + skb_set_owner_w(skb, frame->skb_std->sk);
> > +
> > if (port->dev->features & NETIF_F_HW_HSR_TAG_INS)
> > return skb;
> >
>
> [Severity: High]
> Does the timestamp still get lost on PRP devices?
…
Not really. PTP+PRP is a bit different compared to PTP+HSR. According to
the specification, there is no PRP header attached to PTP message (where
we would need Kernel's sequence number for the packet and so on).
Therefore for the PRP case the prp0 device isn't used but the interface
of the underlying slave device.
> [ ... ]
>
> > @@ -581,6 +585,8 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
> > */
> > if (frame->has_foreign_header && frame->skb_std) {
> > skb = skb_clone(frame->skb_std, GFP_ATOMIC);
> > + if (skb && frame->skb_std->sk)
> > + skb_set_owner_w(skb, frame->skb_std->sk);
> > goto inject_into_stack;
> > }
>
> [Severity: Medium]
> Is it safe to call skb_set_owner_w() here, and in
> hsr_create_tagged_frame(), without checking how the original skb holds
> skb_std->sk?
>
> skb_set_owner_w() adds the clone's truesize to sk->sk_wmem_alloc. It does
> not take an sk_refcnt reference. That is fine when the original skb is
> owned through sock_wfree, which is the usual AF_PACKET case, because that
> charge keeps the socket alive. For comparison, skb_clone_sk() calls
> refcount_inc_not_zero() on sk_refcnt.
>
> An egress skb can carry a socket that nothing pins, though.
> bpf_sk_assign() at TC ingress does:
>
> skb->sk = sk;
> skb->destructor = sock_pfree;
>
> It takes no reference for SOCK_RCU_FREE sockets. The tcx ingress redirect
> path and __bpf_tx_skb() do not orphan the skb before dev_queue_xmit().
> hsr_dev_xmit() accepts any ETH_P_1588 skb with the inline magic,
> whatever its destructor.
>
> Suppose that socket is being closed at the same time and sk_wmem_alloc
> has already reached zero. Could skb_set_owner_w() then add to a zero
> refcount? After the clone leaves the RCU section through the slave qdisc
> or driver, could its sock_wfree() touch the freed socket?
>
> Triggering this needs CAP_BPF or CAP_NET_ADMIN and a narrow close race,
> and the full race has not been shown in practice.
>
> Would it make sense to transfer ownership only when
> frame->skb_std->destructor == sock_wfree, like the copy_dtor check in
> UDP GSO? ip_frag_next() calls skb_set_owner_w(skb2, skb->sk)
> unconditionally, so similar exposure exists elsewhere in the kernel.
That skb arrives from the user on that socket so this skb holds a
reference on that socket. That original skb is returned to the stack
after the skb_set_owner_w() so none of this should happen.
Sebastian
Technical Details
Message-ID:
<20261012153324.fsnDpWZy@linutronix.de>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-345079-linux-kernel-netdev=dewy.ruReferences:
<20261002-hsr_ptp-v8-6-60dabc07e554@linutronix.de> <179129708052.434549.14508967433709198337@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-345079-linux-kernel-netdev=dewy.ru From: bigeasy@linutronix.de (Sebastian Andrzej Siewior) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v8 6/8] hsr: Assign a socket for cloned skbs Date: Mon, 12 Oct 2026 17:33:24 +0200 Organization: Usenet Network Message-ID: <20261012153324.fsnDpWZy@linutronix.de> References: <20261002-hsr_ptp-v8-6-60dabc07e554@linutronix.de> <179129708052.434549.14508967433709198337@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: usenet.network; logging-data="1813686"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:mXCeaEoKhQ+Igugw8b5R/EC8cWs= sha256:Bhp7FYbw7NXc+o7h79K1PVmIG6rdhADirYl3YudQSIE= sha1:/A8yLydyB9iNxutCphFUk7XsnTw= sha256:i9O5fJPRK3BdxbgfY44BIAyhD0ohsFzEyeTLn4AbuRo= 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 953B110FC3C; Mon, 12 Oct 2026 18:44:27 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -0.85 X-Spam-Status: No, score=-0.85 tagged_above=-9999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=linutronix.de header.b=gtv1tFsz; dkim=neutral reason="invalid (unsupported algorithm ed25519-sha256)" header.d=linutronix.de header.b=PVsqozTQ 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 UoMOQP24mILG; Mon, 12 Oct 2026 18:44:23 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-345079-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linutronix.de X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 7CDBB10FC3A; Mon, 12 Oct 2026 18:44:09 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sto.lore.kernel.org (Postfix) with ESMTP id B0662611710; Mon, 12 Oct 2026 15:34:05 +0000 (UTC) X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88D8E49EC7D; Mon, 12 Oct 2026 15:33:31 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gtv1tFsz"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="PVsqozTQ" X-Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 D295449B5C2 for <netdev@vger.kernel.org>; Mon, 12 Oct 2026 15:33:29 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791819211; cv=none; b=DO0pVlC52+p4LDiIr3guUWPBMYFWuh+Y+j0TjZslrv4vPlV+jOqqANWgKIK2VGzM6MFON6AeDNp/FyPurJjGVcKfWyzSDxTvq/SoaCeqSMhynpoEj0NyCW14n4UbzSFj9aZyI893oFkwHgByRheOePuA3jHMLYU/QCn+Ql3isYE= X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791819211; c=relaxed/simple; bh=QKyIDWs4Yg0YOBXKbAJ/BZSzK06X3AdXprSE+BcPPcQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aIrnoCUwVD38CNPmRNFjYqwSa7jrfKk84BxJ+6xq/5UH0Z3Ao4hW+zBXmWRNuldyVJwstR5loU6yFtYSXCV1BVqBq/SezhSnwTcN7YMLc7ZQRelaeKwnU64X83dtXhyQQJUOeou1F4wi7xwWLSNjaLswTxjybSZ0DD+8KJzQpGc= X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gtv1tFsz; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=PVsqozTQ; arc=none smtp.client-ip=193.142.43.55 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1791819206; 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=1osWiF4wkmuhqxvwGegPz+/CYWT5ehZKYMUCxnJOcmQ=; b=gtv1tFszEaGRSl0kRr7yd3aYByuAhexPAVDcF9P5Gf6OOpyKtSwlwOD3q3Kf2dC1V2l+8d k13XHcAPrvLh/r0tWFvHdo1p7XX1knRtksqHJAHS1hfvnKcOvpNd1ltKWkSvXc5QkK70tT lOEbDCyVYKxCXdXyf1CNm2OEwnuu3tDMcrBdnnVGO4kUV/cJ1vVpDHia4zO6Va2kv3bP4h YLxJe/B76waOMQhLxvTpx59qVVk9MjdmaU9Q07EkZoLbNkTVcxKeM1t8wGV1+/nsB4xCxF 28Afthuqpl/MwYCsufszY5Y8RxsSqpaoZsLKGBDo0g4G3RQ7isfynQJs3nr51A== X-DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1791819206; 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=1osWiF4wkmuhqxvwGegPz+/CYWT5ehZKYMUCxnJOcmQ=; b=PVsqozTQJBHJsqkaPvRfv08QW/oxVcsRyv0fAkfhwd2Y31hZk51rE2XwDyT3DU1NOwx9RK g59+f2engnF/p/Dw== X-Cc: netdev@vger.kernel.org, j-rameshbabu@ti.com, andrew+netdev@lunn.ch, c-vankar@ti.com, danishanwar@ti.com, d-qiu@ti.com, davem@davemloft.net, edumazet@google.com, fmaurer@redhat.com, kuba@kernel.org, neelima@ti.com, pabeni@redhat.com, praneeth@ti.com, pratheesh@ti.com, richardcochran@gmail.com, horms@kernel.org, vigneshr@ti.com, willemdebruijn.kernel@gmail.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: <179129708052.434549.14508967433709198337@kernel.org>