From patchwork Tue Nov 29 16:48:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13058867 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C222C433FE for ; Tue, 29 Nov 2022 16:58:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236496AbiK2Q56 (ORCPT ); Tue, 29 Nov 2022 11:57:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236654AbiK2Q5Z (ORCPT ); Tue, 29 Nov 2022 11:57:25 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA72D627C2 for ; Tue, 29 Nov 2022 08:51:42 -0800 (PST) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669740700; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iCnL0qNt30PdSk8bM1mrZseqVehkZGOwmgQKCwV4e64=; b=2TtjJVVitiC2e1kdusFCWE69H1HQmw1jakXmtJN0TTlze2jNaBdE/dZr3dkGdMokipsXS9 M36lBHKAoLmVnviwc/oEiHhVzR9Sdne2cUis2BXhl/TDFLeTSn6ZMkd9U/VRNbD4RvKQTP CmSxafmcT6l7oMRnfalRAwIw3/lqItORhWEsVxRkBkCop0eqtrYjLZGoDw8omwhUgqcC0F Q/CUGPSVzgtvYbgAPXg2ETtuz+XsSAGec+2tRdtXTnToRk32uY3KB+l1p5eRL/UQjCJOeH hBgNYVra0SRt5U/449asaknO7R2HkbTRjfTPjOSebu0FVCHgYDmt0KnyzbhocQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669740700; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iCnL0qNt30PdSk8bM1mrZseqVehkZGOwmgQKCwV4e64=; b=hZSo+A5MZl7Yj+nBGsmJjNMdTo3jPlaUux5RtVavvF9d6oZeEtD/5+PYFN8LOHMoqEGVeX nhNbN9zEFK2JlvCQ== To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Thomas Gleixner , Kurt Kanzenbach , Sebastian Andrzej Siewior Subject: [PATCH v5 net-next 2/8] hsr: Add a rcu-read lock to hsr_forward_skb(). Date: Tue, 29 Nov 2022 17:48:09 +0100 Message-Id: <20221129164815.128922-3-bigeasy@linutronix.de> In-Reply-To: <20221129164815.128922-1-bigeasy@linutronix.de> References: <20221129164815.128922-1-bigeasy@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org hsr_forward_skb() a skb and keeps information in an on-stack hsr_frame_info. hsr_get_node() assigns hsr_frame_info::node_src which is from a RCU list. This pointer is used later in hsr_forward_do(). I don't see a reason why this pointer can't vanish midway since there is no guarantee that hsr_forward_skb() is invoked from an RCU read section. Use rcu_read_lock() to protect hsr_frame_info::node_src from its assignment until it is no longer used. Fixes: f266a683a4804 ("net/hsr: Better frame dispatch") Signed-off-by: Sebastian Andrzej Siewior --- net/hsr/hsr_forward.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c index 9894962847d97..3a97b00b6d978 100644 --- a/net/hsr/hsr_forward.c +++ b/net/hsr/hsr_forward.c @@ -613,11 +613,13 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port) { struct hsr_frame_info frame; + rcu_read_lock(); if (fill_frame_info(&frame, skb, port) < 0) goto out_drop; hsr_register_frame_in(frame.node_src, port, frame.sequence_nr); hsr_forward_do(&frame); + rcu_read_unlock(); /* Gets called for ingress frames as well as egress from master port. * So check and increment stats for master port only here. */ @@ -632,6 +634,7 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port) return; out_drop: + rcu_read_unlock(); port->dev->stats.tx_dropped++; kfree_skb(skb); }