Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6004096rwb; Mon, 5 Dec 2022 06:53:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Yp9HCvrI+GKhs0tbodjSN+CXvwjcNvnfTZeYt2f0E6YtzYb8fX+f9X0hk3tVYxx58wUPs X-Received: by 2002:a17:906:4b08:b0:7c0:f2cf:3515 with SMTP id y8-20020a1709064b0800b007c0f2cf3515mr4559229eju.327.1670252029301; Mon, 05 Dec 2022 06:53:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670252029; cv=none; d=google.com; s=arc-20160816; b=dpJcFm+EwYBXwdOakeHL90QZjwsOoBbSZjfeDlKbJ7VZTBMfc+1CZn9CkazambndWC bTdJYe1u/T84GLSWCIgCHrEHs9Qj3RAm7wiZcGsMBI4+1Ty3+Z/9SvXuyS+WVAwUQYD9 vmLgCRnjN3+XzUMbw9cCcH+2MBZ2a1+jEQD1lJ8aOQ6HdT3yYxglNYrmsIhG/GxEYhvC wIZreKiJonvVye+e04S7J57ddRA5yrDO2m3OXDpypQtfW4ipwy+YgZvYxtr5aqe2b3Gc Fpc4rMyj84gCiykfwFPwhWXsH3KkY7dyxjsHYU7/StYzlVAWqP7DF+QXNOL0lTh86qo4 2OdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=2E7iRCfxSEjczuO8WWx4veRSOiQ14J4EKI+jDiqzJM8=; b=usHl3IPYX73pOfT+7vYHE3qCaQPwqIAHVR0Zsgf+cN4o1WwDAzNk1nNLxDExBn9Pv1 aepgpLnse8Ght/zlXY3Zsquy+lq4azgniaolbJyT9oTVM5skCUCfril2dPvhckeYP+v6 S7N50e9yScAXwpWNKzf2viomOoeKKRYpjGzjCA9f9bLFepCrMBVVjgV38X22V2LdGVYB m504tIRhhsEaKGwpsezGeAkR5G4RSskrfrbDME3OYKje1nqecoe5J+XV/5VHOH09C2nh jSgBE+vJH5KvYnsP+aK5ElI5lIdCOLZwL4sSpmng+DKljrAuhWsxWhGlsXimdG3rgqfA gd0w== ARC-Authentication-Results: i=1; mx.google.com; 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 dm5-20020a170907948500b0078d1dc1b64csi1292126ejc.170.2022.12.05.06.53.29; Mon, 05 Dec 2022 06:53:49 -0800 (PST) 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; 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 S231963AbiLEO2N (ORCPT + 81 others); Mon, 5 Dec 2022 09:28:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231904AbiLEO2L (ORCPT ); Mon, 5 Dec 2022 09:28:11 -0500 Received: from mail.netfilter.org (mail.netfilter.org [217.70.188.207]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C5910BC22; Mon, 5 Dec 2022 06:28:10 -0800 (PST) Date: Mon, 5 Dec 2022 15:28:07 +0100 From: Pablo Neira Ayuso To: Li Qiong Cc: Jozsef Kadlecsik , Florian Westphal , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, kernel-janitors@vger.kernel.org, coreteam@netfilter.org, Yu Zhe Subject: Re: [PATCH] netfilter: nfnetlink: check 'skb->dev' pointer in nfulnl_log_packet() Message-ID: References: <20221202083304.9005-1-liqiong@nfschina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221202083304.9005-1-liqiong@nfschina.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 On Fri, Dec 02, 2022 at 04:33:04PM +0800, Li Qiong wrote: > The 'skb->dev' may be NULL, it should be better to check it. > > Signed-off-by: Li Qiong > --- > net/netfilter/nfnetlink_log.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c > index d97eb280cb2e..74ac9fa40137 100644 > --- a/net/netfilter/nfnetlink_log.c > +++ b/net/netfilter/nfnetlink_log.c > @@ -572,7 +572,7 @@ __build_packet_message(struct nfnl_log_net *log, > } > } > > - if (indev && skb_mac_header_was_set(skb)) { > + if (indev && skb->dev && skb_mac_header_was_set(skb)) { > if (nla_put_be16(inst->skb, NFULA_HWTYPE, htons(skb->dev->type)) || > nla_put_be16(inst->skb, NFULA_HWLEN, > htons(skb->dev->hard_header_len))) > @@ -724,7 +724,7 @@ nfulnl_log_packet(struct net *net, > + nla_total_size(sizeof(struct nfulnl_msg_packet_timestamp)) > + nla_total_size(sizeof(struct nfgenmsg)); /* NLMSG_DONE */ > > - if (in && skb_mac_header_was_set(skb)) { > + if (in && skb->dev && skb_mac_header_was_set(skb)) { > size += nla_total_size(skb->dev->hard_header_len) > + nla_total_size(sizeof(u_int16_t)) /* hwtype */ > + nla_total_size(sizeof(u_int16_t)); /* hwlen */ skb->dev is always guaranteed to be set in this path.