Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1240691pxb; Fri, 21 Jan 2022 13:08:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwuzLTYVNyFsttX15/euhgFUSip6XdkOGk5+Rb1pNoQ9J/vln55yKrj2XFCpMRUzCagXkNC X-Received: by 2002:a17:902:da81:b0:14a:8fda:e321 with SMTP id j1-20020a170902da8100b0014a8fdae321mr5217790plx.96.1642799285489; Fri, 21 Jan 2022 13:08:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642799285; cv=none; d=google.com; s=arc-20160816; b=RX5WLgf/AjxXOtkhWR7pDPZc7vhCC+3dfWYxCWTLQyoHP+odpvvbIV9Eyc3wdeb7gY vSq2oTQWsvuL+8Knq89vsQb4NoG8RinD6uLDwBWDAJHBP7iMqHmWf6t4XqYC6nYlTCl7 xkmmYCzAuRm/Bypej4FHthxeX/OWDwN/vWgp8Cvj5pnXB0BkBguC2x1XKZd2ql2k6219 RLlAYF9USsQYgYO3w0anmmp9O05UB8IJDJe8k+LrwO1U8EmrWKJehWvEvCVcCe9FtxWj Y1LOuXFWf7RmM3luDmNyCumY7jLy/lG99vhd+U9xqRH+R9TgmSavrmqULHdzGyzf+8Qk fHBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SDX/cK3/gxXn/eGgeE8sI/qS5y/GFwfgO+/1Dp/a624=; b=dCh4vFQZGp2wULLEvUJOYNqofV9+EcQ8EMwTLVMXW/UtGXatcC5MHBwXDOqV2nKpIQ 4HP7AypTrK6SW1hTiks1Z5UPZCKCDQCKN2Iuo71HY0unfZEYiwgYSdMEvpU0RsfbQohp 49SJLlHa8NgfCGU2o+GYuGt/azP3+9FTayDFqxwPvlvlnm9FKF0NC48h4z5S5YFAlxhG okZsKPq0O84Zq947VE4aNFLe8kcJ3zgIRB6VS5dp7eNf1D4t9kVSkl6NZvJpF6z8tH/S zd4f0Xrw6ge1Y0csftHIqRYMoAPSbrOhHs2xwFFSH9RCdk5f8Pcw5A7YOZjdVQ0vmR5x k1zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BxwCDDIo; 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 v2si6939655plp.620.2022.01.21.13.07.53; Fri, 21 Jan 2022 13:08:05 -0800 (PST) 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=BxwCDDIo; 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 S1358741AbiATGbV (ORCPT + 99 others); Thu, 20 Jan 2022 01:31:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358734AbiATGbP (ORCPT ); Thu, 20 Jan 2022 01:31:15 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DF8BC061574 for ; Wed, 19 Jan 2022 22:31:14 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 3B82BB81A74 for ; Thu, 20 Jan 2022 06:31:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55985C340E0; Thu, 20 Jan 2022 06:31:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1642660271; bh=Irfj9p2ilfq4lKdinTmm7EYh2n65nyXEfW/EZ4F6L88=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BxwCDDIoxdIbMOX1Z3bDU4RzztcfdvnPW58QvPUat301IajS76TSK3/rK8qCQR2Zj fe55Pnd7ZkwIlNuXr6GnwRqh7sDposyKCL0WvpbzNDuCFVDUIr354K+tHqL5V7dqOv ctOW3Xtm0WTGIyAf4MRrTrN2beEGs+5UzbCXfzeU= Date: Thu, 20 Jan 2022 07:31:09 +0100 From: Greg KH To: Jiasheng Jiang Cc: keescook@chromium.org, dan.carpenter@oracle.com, arnd@arndb.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] lkdtm/bugs: Check for the NULL pointer after calling kmalloc Message-ID: References: <20220120012552.1851621-1-jiasheng@iscas.ac.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220120012552.1851621-1-jiasheng@iscas.ac.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 20, 2022 at 09:25:51AM +0800, Jiasheng Jiang wrote: > 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 explicitly yell about the memory failure and then > 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 > --- > Changelog > > v1 -> v2 > > * Change 1. Add the kfree if fails. > > v2 -> v3 > > * Change 1. Add pr_err if fails. > --- > drivers/misc/lkdtm/bugs.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c > index f4cb94a9aa9c..c64ab6f387eb 100644 > --- a/drivers/misc/lkdtm/bugs.c > +++ b/drivers/misc/lkdtm/bugs.c > @@ -325,6 +325,12 @@ 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) { > + pr_err("FAIL: could not allocate required buffers!\n"); As was pointed out, this is now a checkpatch failure :(