Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp518601pxb; Thu, 9 Sep 2021 06:18:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+jMnGRYkonV2RfH8Tv0BzXjSkUh4/2ZdokXOELvmrxwLwAWWG1BPcQGcvgyPX4RHW5Fv4 X-Received: by 2002:a05:6638:38d:: with SMTP id y13mr2724017jap.139.1631193496819; Thu, 09 Sep 2021 06:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631193496; cv=none; d=google.com; s=arc-20160816; b=0S0qigTozJkx5E+RiY2rUrEsuoF1YOea6pQiXy6WY+infqdfvqXLIQapwCEp3NcBYM x6LJVgh16muEvtoYdrDaty2a24iG1p+dQJTkCycfB7nFrfVsMRDYwpqURypDa4EQf4KV suVD2f2tSsvXEfKXFxOzEyPWtj86I3/SsOF/kR85ouxuLHSKXZtnLfKNcNyMzzP4gOMI fQFrnZkQEEwZmxfl+S18KQOWT3lU3eHrjl4R0J1jSmvt7dcSGIfYiuv5avq7MCOfaSpl 72DRFjxhV5nFxpw2sLEzYVvNuZpnfcGXTreKj0zuPcE5CXIHJkbctOjjV0i9Sb5diXk9 36qw== 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=ItdYTF+97CfGE5vhmCpWGA77KCaF13k/qE4kiUdBAXw=; b=Up204uH7794sOqujLY8rX3E2DkMcUzTmHNzzimaOa6P1WbnhKbE0JvAtj58holfAmR EtO550WlP3gZvaA5o4YPVQ9Lj/yi/lxsrnAjgN01EOILAsz1+hL3hh5F1supsBpESxs/ N5BsazInxgen2LG/ZTlV8H8uk4kKSDg/gyntB/bsUe8WvWLYcKoI2MAfnS+ws+O1LD2B 19sigpZHtlp179zzs4pNBLaO0svGBS/aa9L+JTPn6MHrwomaxb3nRWXEiysjo39V8TCE amjIRIDcUjT0IMnyJt9gLXlbASfPsuNlcVOaydKT/65IJJzHcIXd9wKFmDqTgOTzpRxq 5qDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cCtvAWKm; 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 d10si1629474ios.58.2021.09.09.06.18.04; Thu, 09 Sep 2021 06:18:16 -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=cCtvAWKm; 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 S1359403AbhIINSa (ORCPT + 99 others); Thu, 9 Sep 2021 09:18:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:53482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357894AbhIINFS (ORCPT ); Thu, 9 Sep 2021 09:05:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C78446140B; Thu, 9 Sep 2021 12:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188813; bh=c8mMbslRw07pDGWvcxP/bclbgM7KISmdq3wlbBOK6+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cCtvAWKmBxpj4zHxsdzGZmdUhw6+73m7il3fgS92ZxhhItGfd3DfMkw0aN1V1BL7v h83SeWifIR0R/0TZAzRD9OIuw993wwwYxg0OQn0fcgFoZxH9NYk7oRKf49WWY6FsvS DUepot6xFMBnFkyw1EHCAEmvCTWa299bhw4yrNWb7sBMnrpXggfEx6EfR8LT8fyHIQ TfQRtKxWZU0E4pWi6wC0bDYqEdbk/cOG+CSfycq3aMUBAfDVIRYnus0lvl9uouK3O+ LaRq1JkobSObwvE5AHBAa9L8Oaoxxm94UjErCZCIVHbp5rYh7py0F3kmepN3osX5m8 C0O1jq99nqjJA== 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 4.14 58/59] net: fix NULL pointer reference in cipso_v4_doi_free Date: Thu, 9 Sep 2021 07:58:59 -0400 Message-Id: <20210909115900.149795-58-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909115900.149795-1-sashal@kernel.org> References: <20210909115900.149795-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 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 3e3494c8d42f..28eda7a5267d 100644 --- a/net/netlabel/netlabel_cipso_v4.c +++ b/net/netlabel/netlabel_cipso_v4.c @@ -156,8 +156,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