Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp508900pxb; Thu, 9 Sep 2021 06:07:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7HTlL2sdmw8tmU5EO+soXBoqeQLtheEhfe033Ogx8sZr9kquvpfJy/Joo87rEh2FJ6AqE X-Received: by 2002:a92:cc0d:: with SMTP id s13mr2221719ilp.95.1631192868178; Thu, 09 Sep 2021 06:07:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631192868; cv=none; d=google.com; s=arc-20160816; b=IOPnsxH2wHU0KLrlVWP7paNVQw/XF//XUmX0UCoXByWAJ46LJdGGDDhhD7Wk9dJDfz 4Sm74cuh6kkAukeBadZuc/Z/kWwMx2wA9nWEk9otBNfRa9S8pheKI2LsmoIHuJqPZl3f 4/QqGszfDTMnVamtYXKhUW7YIHWXzvzp8gnxptv3X/pngYMvyJ3G3fD4gWCtwttczmLd SO5X3WQTc2kYd0V/BBFuDd1z2v739HpXLfW3BO5ERpwHMjZa/N5hPgtdl2Kz1mAEupmy yxtsUxlCzEugE3pSnraLVGEjKrN3NNWV4ZmVvHGeubQtfGpQyThjpWOdMoSfJePkFyFV C8/w== 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=xtluVhflI/kXYhCaAFKyZdePzwzo5pMQ6kEo7l1ZU5Q=; b=OsfLI7CpCGf5yONwBf6vNtQ+3MF38A+CpSH9M8O4E0diLIXJfaOJ9wzAcNX74Ggy9h p4/FvZgPPAN8PPFW2U+9JiYr0AWvwwqPNKN7AkQNO8DUg44vOgsYeTzCJIbQsHDpjYto tufvAaLp7Eep3SyWZ8HwBld0XIhg8pttbQth+qtqXVRFx7H/VNeWR6leucdy8WCdxxQ6 znKrTTvdsQSEQopSaK2K5WMd0HdeEv/bWFuPOIQcKfeedDB13FDftebMNlwzCKC6uO3c SBKNQLVcl5+g0xJCqMVu9h8IDax4BIUc4JSzgENHH6ylxC1mu58bL4r5qzW7iQo3wvyh /XxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K62Enwbt; 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 o7si1548038ioh.56.2021.09.09.06.07.34; Thu, 09 Sep 2021 06:07:48 -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=K62Enwbt; 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 S1357709AbhIINEe (ORCPT + 99 others); Thu, 9 Sep 2021 09:04:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:42542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344632AbhIIMvi (ORCPT ); Thu, 9 Sep 2021 08:51:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2ED5663241; Thu, 9 Sep 2021 11:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188643; bh=EKMjStALssU44ZhX8hGhMiLS3Ig+P0p/laQeoBgBD84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K62EnwbtpGkpegU4NxhLPapYqMgwg8GyphCkK9aZXNuhFZyJQSeQN4E9eRvQAYE8f QrXY7HSJOXEvlHrP+9iRxZhhL01BJsvY8i3yIql+Seboe5GNZGaEBOK/SGmvC0k2MD /lHMrN3MQnQH7if4GQquDheBZ4vBYW17VxtnVaTmlP/3kw2TZ+xJhjYY48oGj/nZqJ KG0jfaZrblREZtAiq4yJJrDwH0NxPfBzmOFKW3glihMWy1XyskUQfyelpBcJe79kdY peRjor5WWWK53A0noGz6/z6ftOh1nJbuNuJJg+EjdHKrTZgT68NyfJ7OO0gMAyxrxO Av4sUtOoChqKw== 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.4 107/109] net: fix NULL pointer reference in cipso_v4_doi_free Date: Thu, 9 Sep 2021 07:55:04 -0400 Message-Id: <20210909115507.147917-107-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909115507.147917-1-sashal@kernel.org> References: <20210909115507.147917-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 4cb43a2c07d1..5697d99e18cf 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