Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp933326iob; Fri, 13 May 2022 16:59:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsqtOnJWBXNFbDQJhG4nroSckp7IUidwO2kGdibH7QReLL8URZksvqTNYMl5JzC625NWLl X-Received: by 2002:a5d:648b:0:b0:20c:593f:5ee3 with SMTP id o11-20020a5d648b000000b0020c593f5ee3mr6040174wri.381.1652486371972; Fri, 13 May 2022 16:59:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652486371; cv=none; d=google.com; s=arc-20160816; b=LDHG8laXFtDvL1MBSit2XXOpETXNz3Zj/wbKuTKPdkqfS1C1Ac3cTgj6HsTUpfLxnL KMunrEdCPmiK4Gd086jfhK26+bIN/hFa4L0kp4ja5iUGoW28Wo+9Iwy0k8qUsxynyL4n BF455ABd6kqpHG8eeoEFq6C4SKUm+OuswnGHm3X/FU4pDop6coTSTusxFfh2yDlq2Y1B X9a0N1AI0pNMjWebxAQ5dI01nki2c1XeZJZp0CHZ6L8wGNpJSg6pxVIs8UGp4ZY32mXY SPhxA8yUL1gHbf2VmUOS/nTkcFIlk+/PT1agGqXbLrl/bAWkRT2aXcxiDB6f7Lu91/zg x//Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=3SdSDF7ewAPst9Zo7lkKDOBWvOM46kArH1FoqTvHna8=; b=F8UDowvjeRHmmhUGsd8oW5YG0/Z5+aUfvsJLZ03kqgKzJw9YFHq6XQpqorfvFnezsl sRGOjjj0QBFiMR73vNSSGEXiKUr+H1J7iEh6I5GM4KNhmmJy7Az+4tW0Ei1/nn9xHZhX amLziJX2D6i0kHlmkLQ0rR5eiBkj+prxFNZFSgul0nMK4wBK1uuteSsGb/o3uF/wOP7n O6hiYjcq6FOY6bE9eSqPNSpfEta+JBMK2ZmumLxTGExFYKtULZDKrw5LbZr8YQuT/WuU 85afwyL0A6og4r6SYzabt8iSlrrxM+xNz51f783lttxFFHLZK6Pyf6xmbUZBPIdTQvGn gqZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TVp08MhC; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r81-20020a1c4454000000b00394788a24ebsi3699377wma.47.2022.05.13.16.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 16:59:31 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TVp08MhC; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3E88426573; Fri, 13 May 2022 16:00:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382223AbiEMPgr (ORCPT + 99 others); Fri, 13 May 2022 11:36:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382225AbiEMPgb (ORCPT ); Fri, 13 May 2022 11:36:31 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE941101C4; Fri, 13 May 2022 08:36:30 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id l11so7813401pgt.13; Fri, 13 May 2022 08:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3SdSDF7ewAPst9Zo7lkKDOBWvOM46kArH1FoqTvHna8=; b=TVp08MhCiNH0J+l+jaKpwd6/jEhJwrKLGROYxtsWMbZtxKkoazCgcygWI6LQCYJolJ MAZrTo+W8GtQ3TyTDG6JrAB+JaSpBmLtNxfuQ8kNlqWUuscAKZ89Na7gxlMNG9nHJJ8d aPMXuLpWESRR3NWDfWZHv0eEO6nSo9bQJHzgADVVyX6nBaLbOSK83bileRGefnX0baqD aDqIb7lPh79moQXIiaNSJzPqPVBQ8dgImJ+4p81EFoGWVP9frz0eMBTYmP7WhrC2vrIU EwY8bSI/U6o+3gYIhlMOWpPRyAl0dMUi2AzDPeRYqIySs/18Jdy3X4Gexw7+BpNRTDXG QqwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=3SdSDF7ewAPst9Zo7lkKDOBWvOM46kArH1FoqTvHna8=; b=AtUqOfWkKmSIKPBTe7yzIpL27GJnoaUgpLDjXg70qx9nJTITzcMs5qK1XQaGbfBSkn 8KqyAam1Zszmxv2qrTX8FGXRx8ND/B1jVjCa8Sgt9IH5yDk4B/J8QusxcEviQVgB6tJs uyMaji4B9fmfqp7yCaGJSKI4k+UuidScjvBv5hchgOGjSVWNkSSN/WG7K2OcqFmOCI8r jFrxRigyNZaCsSv1dVdsxV2a7IbLlkwZnKnpF53Zrmyb+tAcslmwuaN6OvivfVExT1Lz Sj6ACx2ANOTIPSS/RwMyhyfpB+YxNtGJWQH18gSN8ZRGashuUys5Au3HnF2IgwGftSuE r1CQ== X-Gm-Message-State: AOAM53082O1Z1iKT0sdiTO0q31qzwBq1FGMcZjSp0h/9t9cqFiiGRbBC BtcnHKNnEZEG4ejsZ3Q+pIk= X-Received: by 2002:a62:6410:0:b0:4f3:9654:266d with SMTP id y16-20020a626410000000b004f39654266dmr4980430pfb.59.1652456190365; Fri, 13 May 2022 08:36:30 -0700 (PDT) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id b10-20020a62a10a000000b0050dc762817dsm1942137pff.87.2022.05.13.08.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:36:30 -0700 (PDT) Sender: Vincent Mailhol From: Vincent Mailhol To: Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Max Staudt , Vincent Mailhol Subject: [PATCH v2 2/2] can: dev: drop tx skb if in listen only mode Date: Sat, 14 May 2022 00:36:06 +0900 Message-Id: <20220513153606.302464-3-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220513153606.302464-1-mailhol.vincent@wanadoo.fr> References: <20220513142355.250389-1-mailhol.vincent@wanadoo.fr> <20220513153606.302464-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Frames can be directly injected to a can driver via the packet socket. By doing that, it is possible to reach the net_device_ops::ndo_start_xmit function even if the driver is configure in listen only mode. Add a check in can_dropped_invalid_skb() and to discard the skb if CAN_CTRLMODE_LISTENONLY is set. Signed-off-by: Vincent Mailhol --- drivers/net/can/dev/skb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c index 8b1991130de5..f7420fc43b99 100644 --- a/drivers/net/can/dev/skb.c +++ b/drivers/net/can/dev/skb.c @@ -5,6 +5,7 @@ */ #include +#include /* Local echo of CAN messages * @@ -286,6 +287,7 @@ static bool can_skb_headroom_valid(struct net_device *dev, struct sk_buff *skb) bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb) { const struct canfd_frame *cfd = (struct canfd_frame *)skb->data; + struct can_priv *priv = netdev_priv(dev); if (skb->protocol == htons(ETH_P_CAN)) { if (unlikely(skb->len != CAN_MTU || @@ -299,8 +301,13 @@ bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb) goto inval_skb; } - if (!can_skb_headroom_valid(dev, skb)) + if (!can_skb_headroom_valid(dev, skb)) { + goto inval_skb; + } else if (priv->ctrlmode & CAN_CTRLMODE_LISTENONLY) { + netdev_info_once(dev, + "interface in listen only mode, dropping skb\n"); goto inval_skb; + } return false; -- 2.35.1