Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp662275iog; Mon, 13 Jun 2022 10:06:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uGtQjSFVatiaHG8MZZCE66Nt74C7NFRQvAP6vfcaNSJ7tsozYDGNDh8Hq8HSnibSx1qLs/ X-Received: by 2002:a17:903:258b:b0:163:cf73:c083 with SMTP id jb11-20020a170903258b00b00163cf73c083mr271671plb.127.1655139988758; Mon, 13 Jun 2022 10:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655139988; cv=none; d=google.com; s=arc-20160816; b=JYqJb1cY+t+EbGLvDKVIUvHd17ipBTySYiO0MN4h7sEpA9nCQ4mF+Uy54jtmNBuqqW gxrz9UrhaBXlM8WOyrvfobdj7VIkPodIuR89KVd8Su5gUMbcfyVib3H/C0rBXUEkZLtU D37rbW58NRzE8ihHAZo/Sy4zBTavd7D854oP/vubu78ZNssVPcpJVKsZOJ3I6QWPX+5K 72qqlRj9Fbh85V/7J3NdCEBVr8pla8pI9eKjRIf5anUqx5qg63Fhd+g0e+bq/s4rw3Ap 5f5Rv9BD72Uw9jRFqYUmh+eTuqNFws7DccC6eqmMY6rKPo1nlIrrHQXEKAe02HVL6wm/ toww== 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=sDflSdn7eNuiJmZ32lSTftaNcb8Tp5q7IJzWqRbLbCs=; b=IEun20+qiyLyhTI6DCkSZ9P3McRafJ0wLsQU+z9r94Su/bwAAzQzOTGrKdBA4+1f0C XIb46LQaVNpjcetXzPRgpp4ktPj5fGWuweuig+ZOXPf/1AfpvljkvKbnbXz/InkacF+8 ooc5FBvuGV1WqRhXPjhJqJc690SJJT+HEn1G2etjf1iT4rWCzEu40pZ2Jen11pk7iazF Rv8sbUbDDsRkQiSyeTTQRnYvX5LfV0OTfGsOpbTPfM5zjETR04intMQ1DHFQlQ8WtGeR 0t1xadw9sjAXAHNfbJ0Ysj3wmsM1Noh/MHgM68E4d5PM0Ke+NNkuMTgslRulYcy+ON7b wqhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rc4RFm1A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 185-20020a6302c2000000b003fa55035251si9664757pgc.820.2022.06.13.10.06.15; Mon, 13 Jun 2022 10:06:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rc4RFm1A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1353513AbiFMMze (ORCPT + 99 others); Mon, 13 Jun 2022 08:55:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356316AbiFMMyA (ORCPT ); Mon, 13 Jun 2022 08:54:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2663C3F32E; Mon, 13 Jun 2022 04:12:51 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 93C1860B76; Mon, 13 Jun 2022 11:12:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4A02C34114; Mon, 13 Jun 2022 11:12:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655118763; bh=H9Mml7Wvm3lhnTaVOjmzCox/xg4okfnoDXKTBsKkDo0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rc4RFm1AdL/IeQn1iXWkkj77dFjWnhmDzAvhycJDADc0+yGWzC15kUY8dPSqNsvS7 aDdIvnhhriP2PRsuQoypN2RBhbdrhX0nXYzUw9FRYmpLaFh67zYEXp56DbQTf4I4g2 LTot5xqNoKLWXlivVUv+8pIx0YSAzJmKM5QvVH7A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiasheng Jiang , Dan Carpenter , Kees Cook , Sasha Levin Subject: [PATCH 5.15 004/247] lkdtm/bugs: Check for the NULL pointer after calling kmalloc Date: Mon, 13 Jun 2022 12:08:26 +0200 Message-Id: <20220613094923.032482667@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiasheng Jiang [ Upstream commit 4a9800c81d2f34afb66b4b42e0330ae8298019a2 ] As the possible failure of the kmalloc(), the not_checked and checked could be NULL pointer. Therefore, it should be better to check it in order to avoid the dereference of the NULL pointer. Also, we need to kfree the 'not_checked' and 'checked' to avoid the memory leak if fails. And since it is just a test, it may directly return without error number. Fixes: ae2e1aad3e48 ("drivers/misc/lkdtm/bugs.c: add arithmetic overflow and array bounds checks") Signed-off-by: Jiasheng Jiang Acked-by: Dan Carpenter Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20220120092936.1874264-1-jiasheng@iscas.ac.cn Signed-off-by: Sasha Levin --- drivers/misc/lkdtm/bugs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c index 4282b625200f..072e3b742edf 100644 --- a/drivers/misc/lkdtm/bugs.c +++ b/drivers/misc/lkdtm/bugs.c @@ -248,6 +248,11 @@ void lkdtm_ARRAY_BOUNDS(void) not_checked = kmalloc(sizeof(*not_checked) * 2, GFP_KERNEL); checked = kmalloc(sizeof(*checked) * 2, GFP_KERNEL); + if (!not_checked || !checked) { + kfree(not_checked); + kfree(checked); + return; + } pr_info("Array access within bounds ...\n"); /* For both, touch all bytes in the actual member size. */ -- 2.35.1