Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp462133pxb; Thu, 9 Sep 2021 05:08:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy+0d2PWWMVxGgMq6mSiaxSRBng8cm4TUdQnW8fJqOM9OZwHEli36wHW7OTEG5bnplY+kT X-Received: by 2002:aa7:d0c9:: with SMTP id u9mr2797919edo.167.1631189306918; Thu, 09 Sep 2021 05:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631189306; cv=none; d=google.com; s=arc-20160816; b=WRVZr4JT+6HGHJFAjo3eX201LE+vlk1LYqadNmiWGVaz9IGPaOe7dWLbSbYYXjw4ep TfhIiSeR4Epyn5qZHhW0m8f1P/rT8lSBdZiUOugvS8Cuxnm7KOx9gyI2UtZm2vuiXqzA BFeTQ/HBuBzJ2mSCriNC5a8gA7yJqWf8PuVcCD40Cw7vYCbhHSFIfHj83SOTjTBLncnb StuDz+doY4tMIGX0OeVt8FZhE6waVsFCkTUPMR4cO3ikphJ0OvQtaOU0ZM+MbnRhsjUy VfoOkFmA4LyDNI420c0s0lU1igI5rdZcU0bph38K6g+yZjS/GjIUlmjZGzGO0S0jwdLM AQqg== 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 :dkim-signature; bh=9MGnsWqigCarrFuxTMv/cuF/zNmi5b+iVzjysixgxWg=; b=IWmuoCWwcRR5XvFWkSnP83vaVdF1PPXxAPOP2w5HXKdcsY3EZeiaU8Zo5caHrlIYah oEFq0Je/oca6LEjNgtQmZRjk4cgjxi4OVWEmtKMTXfXR2CgJW4VeupAuq8hp6pLo9QE6 M8iftUdOnx11xFcpPzeTEP4MNyNZavxhLTkf6ahii1cEZ+w/DXhaLbxWoaxRa1xjvXlm rmaWRPUx/LJj2OmEPv6opFV1jhwC+C0F9gv/KissZzlSxoFKcIJcvFUZFxuVCkEQLhEW bpETWze9z7nbLZ2QoF4jisl9R3NjWJ9oqgeU2F4Jg3+WcrGk2L4A3ubLCSudtVFrkeFx n7hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jxn/8laE"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hs3si2413086ejc.368.2021.09.09.05.07.56; Thu, 09 Sep 2021 05:08:26 -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=@kernel.org header.s=k20201202 header.b="jxn/8laE"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345404AbhIIMHJ (ORCPT + 99 others); Thu, 9 Sep 2021 08:07:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:41778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241971AbhIIMBy (ORCPT ); Thu, 9 Sep 2021 08:01:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F28E461529; Thu, 9 Sep 2021 11:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187989; bh=Z1J+GZT3Lz0vIpsQ8HHq28e6VW94O/FvX+kVIt+pYvQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jxn/8laEwDfBLNuGoED2YNp6SJWOgCD6PjWvaH9jI9MjaXbIe8MWGdxkqo4N9UEAf ct/vA+m8rexPtIjNKSspCIRv9NY+k+3K6UNBRRFWwEZWJOwky+dAUQFIuPoYeUoDF9 am6ci1HPjKz+Agfe3XC4BY/dyD5/eUoOoZa4PLJnRAgagMufpAkNJ7tztg8MSBVbzp s95shSrKe4sBk696AiMOyhgPaOqn5/SYNUCOkTCzGTajSJxUKcTKmxuXa3bWwl0Z4e r7czoll70CGac4BfjhFE7x/p49tAb06MlaSnUfhqKHIllgqmXQMs5/r0B5sYCb+t1t 2pa2oe6fhs/jw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?=E7=8E=8B=E8=B4=87?= , Abaci , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH AUTOSEL 5.14 249/252] net: fix NULL pointer reference in cipso_v4_doi_free Date: Thu, 9 Sep 2021 07:41:03 -0400 Message-Id: <20210909114106.141462-249-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 e842cb60e8ac1d8a15b01e0dd4dad453807a597d ] 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 got value 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 in 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 baf235721c43..344c228005f8 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