Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1733490pxb; Thu, 16 Sep 2021 14:17:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpmjtlRxHcU9JE5u5vNmMuTv5Ec/GeF6LBdooERld6S8BXJk/piDXiiEIwNvQfLl/hNYg0 X-Received: by 2002:a92:cd46:: with SMTP id v6mr5501054ilq.66.1631827020122; Thu, 16 Sep 2021 14:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631827020; cv=none; d=google.com; s=arc-20160816; b=ScAU74Y4zpLcYX+TSVNdizq1IErL+firPrkf8Bmdl1nVRXh2ZC/DWN6SzQzyAnV2Vq b+6zGnRUyPd2r3y2DdYTPp3DdHbDuaFgKOdLPWm8snV54RA6NFE2u9eHpMTCxxz+Jf+c dqIR122jbQzs7b5PHcWPigSuOk7I9zVgGaawVWryWBZKKKpWh6wVr4BAKCQFh3z7xokA S18vZacmsQEKvrdL5X2apmqQbiblB5FsOiq7QybkIWmgAPlCG3NX11c2kqEiI2LQMFdH kMBJXaHez2Fq4vTOzhELhEleEusKHgb/k/bZWrMAlW6FOZeyvWcguIg+0XGOQ+v7UjTu GujA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mqCkBygbCp2US0DmwrBbBGC6AX01fNlHDcfC3ZSZ+nM=; b=lWDiCcVAbW2+Eu8kMCOO0LxWWZNhZiaVmt9VYQE0baVlqQqRdyTTag79sbpgaJysfh XU6iZB3BdDXUOQENOZEYpA/t0dnHEP17z5jDSfl5J+lKEqUlvjIonyBGdgfhmJGcdVeQ eHO8IjnDOaZTk8+44AfrdVLT9eLEkoGSHqKrMZQ6H3HJ8f8+GhMFTLnWv8aIq/XPax0q cn7hA+6oyRCMrkdEQaNIL5a5iazMmQmBflxFuHGWeQJHwd3KBa5olbrYjHOF3dwuJ0TY xETXg1CbCyJ67JzuJTzuxrcwxbaYVK9BHIDmlGQHXdsmrHLWn0cczfJM+C8lrx3GxJtD S2hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jurpy0iT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z14si3797668ill.35.2021.09.16.14.16.49; Thu, 16 Sep 2021 14:17:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jurpy0iT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241869AbhIPQbS (ORCPT + 99 others); Thu, 16 Sep 2021 12:31:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:58820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241181AbhIPQXO (ORCPT ); Thu, 16 Sep 2021 12:23:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A2D8D61423; Thu, 16 Sep 2021 16:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808932; bh=cytdpkDYbEeqgmMYI47aiKliJqKFscmNN8PkvP5xabU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jurpy0iTnJ5l+9HCmtQBdidbEQ5eZPtwqHbG6A1GiuyiNoZvJhXGhGjZdvlYMrT0R 1N6msOBAnhP+RYs1wPIJ2CfWLYZlZpQXJrYjMOM5op2DXS/y7x7wCLd0lYByEu/XLv dcgpzcwFcr23lSgg48jM47Rp6+9p/zuwlHy84Z7U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Abaci , Michael Wang , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 274/306] net: fix NULL pointer reference in cipso_v4_doi_free Date: Thu, 16 Sep 2021 18:00:19 +0200 Message-Id: <20210916155803.421191781@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: 王贇 [ Upstream commit 733c99ee8be9a1410287cdbb943887365e83b2d6 ] In netlbl_cipsov4_add_std() when 'doi_def->map.std' alloc failed, we sometime observe panic: BUG: kernel NULL pointer dereference, address: ... RIP: 0010:cipso_v4_doi_free+0x3a/0x80 ... Call Trace: netlbl_cipsov4_add_std+0xf4/0x8c0 netlbl_cipsov4_add+0x13f/0x1b0 genl_family_rcv_msg_doit.isra.15+0x132/0x170 genl_rcv_msg+0x125/0x240 This is because in cipso_v4_doi_free() there is no check on 'doi_def->map.std' when 'doi_def->type' equal 1, which is possibe, since netlbl_cipsov4_add_std() haven't initialize it before alloc 'doi_def->map.std'. This patch just add the check to prevent panic happen for similar cases. Reported-by: Abaci Signed-off-by: Michael Wang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/netlabel/netlabel_cipso_v4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c index 50f40943c815..f3f1df1b0f8e 100644 --- a/net/netlabel/netlabel_cipso_v4.c +++ b/net/netlabel/netlabel_cipso_v4.c @@ -144,8 +144,8 @@ static int netlbl_cipsov4_add_std(struct genl_info *info, return -ENOMEM; doi_def->map.std = kzalloc(sizeof(*doi_def->map.std), GFP_KERNEL); if (doi_def->map.std == NULL) { - ret_val = -ENOMEM; - goto add_std_failure; + kfree(doi_def); + return -ENOMEM; } doi_def->type = CIPSO_V4_MAP_TRANS; -- 2.30.2