From nobody Fri Dec 19 18:59:40 2025 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 8EAE9C19F2A for ; Mon, 1 Aug 2022 12:00:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232849AbiHAL76 (ORCPT ); Mon, 1 Aug 2022 07:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232912AbiHAL7P (ORCPT ); Mon, 1 Aug 2022 07:59:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55B5F4B0E5; Mon, 1 Aug 2022 04:52:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DC1FAB81171; Mon, 1 Aug 2022 11:52:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 541F9C433C1; Mon, 1 Aug 2022 11:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1659354751; bh=Q5E1jl/+1O97q4wtu2UZwV9sc9s4f7+lg7q+Pf8jJeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bE7b5RGpSah9kxsY340c9hktA7hwx7BvKevqFLaDpSV0RcDlbqUUKHCWFEtXVEdJH xXMM43BfyfieoW3o3FNkwNBKeVKkEJdDrEGLZUmGkvJ2/Y4s3Ix7aKjKeVZMFfioKk PAgupHpDZoGj/afTAGH0+LR8CmpG3P1eK1EDP9/k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Frantisek Sumsal , Sabrina Dubroca , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 31/65] macsec: fix NULL deref in macsec_add_rxsa Date: Mon, 1 Aug 2022 13:46:48 +0200 Message-Id: <20220801114135.010489346@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801114133.641770326@linuxfoundation.org> References: <20220801114133.641770326@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sabrina Dubroca [ Upstream commit f46040eeaf2e523a4096199fd93a11e794818009 ] Commit 48ef50fa866a added a test on tb_sa[MACSEC_SA_ATTR_PN], but nothing guarantees that it's not NULL at this point. The same code was added to macsec_add_txsa, but there it's not a problem because validate_add_txsa checks that the MACSEC_SA_ATTR_PN attribute is present. Note: it's not possible to reproduce with iproute, because iproute doesn't allow creating an SA without specifying the PN. Fixes: 48ef50fa866a ("macsec: Netlink support of XPN cipher suites (IEEE 80= 2.1AEbw)") Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D208315 Reported-by: Frantisek Sumsal Signed-off-by: Sabrina Dubroca Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/macsec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 789a124809e3..0b53c7cadd87 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -1750,7 +1750,8 @@ static int macsec_add_rxsa(struct sk_buff *skb, struc= t genl_info *info) } =20 pn_len =3D secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN; - if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) !=3D pn_len) { + if (tb_sa[MACSEC_SA_ATTR_PN] && + nla_len(tb_sa[MACSEC_SA_ATTR_PN]) !=3D pn_len) { pr_notice("macsec: nl: add_rxsa: bad pn length: %d !=3D %d\n", nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len); rtnl_unlock(); --=20 2.35.1