Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F35DC636CC for ; Thu, 16 Feb 2023 02:26:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229574AbjBPC0s (ORCPT ); Wed, 15 Feb 2023 21:26:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbjBPC0p (ORCPT ); Wed, 15 Feb 2023 21:26:45 -0500 Received: from mail.nfschina.com (unknown [42.101.60.237]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA4E232CEA for ; Wed, 15 Feb 2023 18:26:43 -0800 (PST) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id E6D771A00A5E; Thu, 16 Feb 2023 10:27:18 +0800 (CST) X-Virus-Scanned: amavisd-new at nfschina.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (localhost.localdomain [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id O873CoC8MC4m; Thu, 16 Feb 2023 10:27:18 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: zeming@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 1AA2F1A00A0E; Thu, 16 Feb 2023 10:27:18 +0800 (CST) From: Li zeming To: keescook@chromium.org, arnd@arndb.de, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Li zeming Subject: [PATCH] lkdtm: perms: Increase pointer assignment check Date: Sat, 18 Feb 2023 02:58:01 +0800 Message-Id: <20230217185801.3232-1-zeming@nfschina.com> X-Mailer: git-send-email 2.18.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Increase the check after the pointer allocates memory. If these two functions are used, at least increase some robustness. Signed-off-by: Li zeming --- drivers/misc/lkdtm/perms.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c index b93404d65650..a5d8dce5ce49 100644 --- a/drivers/misc/lkdtm/perms.c +++ b/drivers/misc/lkdtm/perms.c @@ -180,15 +180,19 @@ static void lkdtm_EXEC_STACK(void) static void lkdtm_EXEC_KMALLOC(void) { u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL); - execute_location(kmalloc_area, CODE_WRITE); - kfree(kmalloc_area); + if (kmalloc_area) { + execute_location(kmalloc_area, CODE_WRITE); + kfree(kmalloc_area); + } } static void lkdtm_EXEC_VMALLOC(void) { u32 *vmalloc_area = vmalloc(EXEC_SIZE); - execute_location(vmalloc_area, CODE_WRITE); - vfree(vmalloc_area); + if (vmalloc_area) { + execute_location(vmalloc_area, CODE_WRITE); + vfree(vmalloc_area); + } } static void lkdtm_EXEC_RODATA(void) -- 2.18.2