From nobody Sat Apr 18 12:47:01 2026 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 95DC2CCA479 for ; Thu, 14 Jul 2022 01:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231955AbiGNB11 (ORCPT ); Wed, 13 Jul 2022 21:27:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbiGNB10 (ORCPT ); Wed, 13 Jul 2022 21:27:26 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7FCE20F77; Wed, 13 Jul 2022 18:27:23 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4LjxcF2fnvz1L95n; Thu, 14 Jul 2022 09:24:45 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.58) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 14 Jul 2022 09:26:58 +0800 From: Xiu Jianfeng To: , , CC: , Subject: [PATCH RESEND -next] lsm_audit: Clean up redundant NULL pointer check Date: Thu, 14 Jul 2022 09:24:21 +0800 Message-ID: <20220714012421.55627-1-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.58] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The implements of {ip,tcp,udp,dccp,sctp,ipv6}_hdr(skb) guarantee that they will never return NULL, and elsewhere users don't do the check as well, so remove the check here. Signed-off-by: Xiu Jianfeng --- security/lsm_audit.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/security/lsm_audit.c b/security/lsm_audit.c index 78a278f28e49..75cc3f8d2a42 100644 --- a/security/lsm_audit.c +++ b/security/lsm_audit.c @@ -44,9 +44,6 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb, struct iphdr *ih; =20 ih =3D ip_hdr(skb); - if (ih =3D=3D NULL) - return -EINVAL; - ad->u.net->v4info.saddr =3D ih->saddr; ad->u.net->v4info.daddr =3D ih->daddr; =20 @@ -59,8 +56,6 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb, switch (ih->protocol) { case IPPROTO_TCP: { struct tcphdr *th =3D tcp_hdr(skb); - if (th =3D=3D NULL) - break; =20 ad->u.net->sport =3D th->source; ad->u.net->dport =3D th->dest; @@ -68,8 +63,6 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb, } case IPPROTO_UDP: { struct udphdr *uh =3D udp_hdr(skb); - if (uh =3D=3D NULL) - break; =20 ad->u.net->sport =3D uh->source; ad->u.net->dport =3D uh->dest; @@ -77,8 +70,6 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb, } case IPPROTO_DCCP: { struct dccp_hdr *dh =3D dccp_hdr(skb); - if (dh =3D=3D NULL) - break; =20 ad->u.net->sport =3D dh->dccph_sport; ad->u.net->dport =3D dh->dccph_dport; @@ -86,8 +77,7 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb, } case IPPROTO_SCTP: { struct sctphdr *sh =3D sctp_hdr(skb); - if (sh =3D=3D NULL) - break; + ad->u.net->sport =3D sh->source; ad->u.net->dport =3D sh->dest; break; @@ -115,8 +105,6 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb, __be16 frag_off; =20 ip6 =3D ipv6_hdr(skb); - if (ip6 =3D=3D NULL) - return -EINVAL; ad->u.net->v6info.saddr =3D ip6->saddr; ad->u.net->v6info.daddr =3D ip6->daddr; /* IPv6 can have several extension header before the Transport header --=20 2.17.1