Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp8590683ioo; Sat, 4 Jun 2022 12:32:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNhQGBCxj+nkQD7E8bVaytY50ZUOHXsulOQZZQor7FaDlhTSbTz8YKZpSnjugunrpA2gXu X-Received: by 2002:a17:90b:17d2:b0:1e2:c0a2:80fb with SMTP id me18-20020a17090b17d200b001e2c0a280fbmr41170281pjb.67.1654371170343; Sat, 04 Jun 2022 12:32:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654371170; cv=none; d=google.com; s=arc-20160816; b=sZBYKqLUh89g6qSqFrv24E7p/EUGypOVhFQf+2O0rxLfo1031njGbKgp77QN++/+qM U5oR5hT9NwizKmRFnVQT3ZY0E2cNkKDwxCxUgMSGQolMfOkKadz2vYmrPqS292qT8hQx 2uWfy1zcTo/g0VBSuCsGvYtGa07RDp+WXkAm6jEulKpFD/mcKW6nqLvc5E/parSRXrfR YeMeUo65S9rAzWGk+Zfx0gaQJlnZ4DDtYkW0GZlwBow3uEGFodJzqq3eabXfl4eCkzuq SuIlUEssBgLM5GBqevOP/+bZ8dJZJBG0faZ/DCsmE6mxEkRsDKScNeE8K9TWx5t98mwU crPQ== 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=wPNc3YvhAKuZLbvOFj+YsMRBSINjKQKB6Tw7aOecxnY=; b=eqNaBTHMNlrytmELRNsGBBQ3oLOpjzIbVQoMMnsKYFaZZbEWHuwExz2JIWEt6NScOO lrZwyLKtnYjeOO8V3A2q5WP06XOgwi2aA5s11DWrpQx0jf8JdYvBBziooGYxfgPUPDaO oa/ZWib1vMDN5zMRYf5wPWYsvCl6e8IvC4/ljoY86wMopomCLu9bz5pjllNwQ2NeUy9j MEmw25HXtDqh9Engpy/MC6VuYKl4Mgt9zVTjsrkWYGaDjuKLmiP7+OogZWsS/hrwa4SD Mq8BfusVNOUQlRLCRc1akgsRNWtDu+UwXHsdH5f9EiMtNiefd2ThqNlTEwHBD93wgSGQ gbGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="fjr/YLTf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b14-20020a63e70e000000b003fbe01f7485si5279489pgi.648.2022.06.04.12.32.38; Sat, 04 Jun 2022 12:32:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="fjr/YLTf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243834AbiFCKav (ORCPT + 99 others); Fri, 3 Jun 2022 06:30:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243703AbiFCKaH (ORCPT ); Fri, 3 Jun 2022 06:30:07 -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 2A3283B3F8; Fri, 3 Jun 2022 03:30:06 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id g184so6924325pgc.1; Fri, 03 Jun 2022 03:30:06 -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=wPNc3YvhAKuZLbvOFj+YsMRBSINjKQKB6Tw7aOecxnY=; b=fjr/YLTf3JpqKnGPXEQKWeEulEUL8Cbj+DXC0/q/+SmEvIEwQN+MSO/KtRcHNn0rJk eUSFlvhs5UgDYRyVN6rLyBer6rEPqmDE2tWw0YhIlwI3hJF5s4IjVSjWuKp1DyE6Qz5B y3VUQgTdrgZeU1+9bWiD3+4oWVieffOuFQe3azHhxy7kbM/UeatWVzSobWW8fspD4xSE lipg7a4myWbMi/MShhgm8UgYmzPZs3TZkXW9bsqyygYlEkwQlOkjUejz/VhjO+8eJ3ET 7WHn+dgANiC/saQ2YKliXM6bmBHpSH16MpatSgt4+vh+jwuZyRyekz6kP5htvHuvbj6x fSIA== 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=wPNc3YvhAKuZLbvOFj+YsMRBSINjKQKB6Tw7aOecxnY=; b=BuKQltO/EsD8CWvtXvzwTcvPBYGMR7UO9NhLVYbIZ7rCDSw1B1fgFl68KVyzLnujvL wRUWJQ4pgaD6NartZWr5S7UuqpvSBTVG6g6tExGW5L5NFCiSXzO3v7UbgOsLpkgEJg7U x9WxEs4T49FPEZv+E+9g7o4jeefjBIDz5lBciCcOgFUr7StTDbQHHQxXNOSuE5A69CAy UJd5eIK5cmAYejQX1X4n6EIkPtYN/5vPtGu5ukYmzahI3SZNbCfTtiMAkSOYgvNnQ8+C yXx8h4J9UPWM7x7R2sa49JXKT3X2htvrck16yQ/d5jlpswwILb6Z+6xiSqvGYgCmHCct zpwA== X-Gm-Message-State: AOAM530XAQGGCw1laRJLv/7Y+fL3K/DET3rneZVGyNTbVckUJtrFEy/E DeKLwM3htbCBZb0GS/7IZoQ= X-Received: by 2002:a05:6a00:1c4e:b0:51b:ebf1:53c4 with SMTP id s14-20020a056a001c4e00b0051bebf153c4mr492238pfw.49.1654252205674; Fri, 03 Jun 2022 03:30:05 -0700 (PDT) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id b22-20020a056a0002d600b0050dc7628182sm3041676pft.92.2022.06.03.03.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:30:05 -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 , Oliver Hartkopp , netdev@vger.kernel.org, Vincent Mailhol Subject: [PATCH v4 7/7] can: skb: drop tx skb if in listen only mode Date: Fri, 3 Jun 2022 19:28:48 +0900 Message-Id: <20220603102848.17907-8-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> References: <20220513142355.250389-1-mailhol.vincent@wanadoo.fr> <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,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 so, it is possible to reach the net_device_ops::ndo_start_xmit function even if the driver is configured in listen only mode. Add a check in can_dropped_invalid_skb() 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 dc9da76c0470..8bb62dd864c8 100644 --- a/drivers/net/can/dev/skb.c +++ b/drivers/net/can/dev/skb.c @@ -5,6 +5,7 @@ */ #include +#include #include #define MOD_DESC "CAN device driver interface" @@ -293,6 +294,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 || @@ -306,8 +308,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