From patchwork Fri Feb 17 18:58:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li zeming X-Patchwork-Id: 57814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp61544wrn; Wed, 15 Feb 2023 18:32:51 -0800 (PST) X-Google-Smtp-Source: AK7set+QcjDEGqVgv74QSH8yKBiYwxCwFwRulgqwmOPcOA5Kqta+cZUxGhx+mzkAXGh3AQjMFPdH X-Received: by 2002:a17:907:b60d:b0:88d:ba89:1839 with SMTP id vl13-20020a170907b60d00b0088dba891839mr744696ejc.10.1676514771553; Wed, 15 Feb 2023 18:32:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676514771; cv=none; d=google.com; s=arc-20160816; b=hZ4wJdCSQ0RSC3H+7pSpUbky1S1u+VY5v+m1DzN8CPDJRbZQRfxd2sKktDRimhcRo3 F5km67MzX0uicBwzSVpNIFDRsP7fEJjJzojU9pwqy7tuSmOX3G7LHzbRzXE370jPCBxu LJHvbfcQjz0xWO91LEtLgDJmQi7ln3TcAetcknbVCV9HLlL7iNhT8hOXoIYYZ3dUx8bu XCZS8tzT1Rf0gvxD7tlOVAJItyC8ucHId75/cyOrcaXGv8Xh18BZr+3xO2SDVH7if3ll +oSDOi8Zr8YPr+ZeGFKSQfnPpl+sXPC/1jm3Wf8NfOrloE7RdbXHsjpzYZYmaZcPtTBM p3iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=nypg662RgBabBMV1t1WMxLl+eMQppMuOURdt7bTuTcA=; b=ZifbRTQe8jQiFXMmOz1fCyziiL09/VhktfHYIJjiQGX5BsQQuy7rAQPIBwGW0jZscL TAKxzYDvs/vRDUCv8rQBeIibl3pjdCmEM726MnFWyYwZM7Eq5/dYU7BWKR5Bifxkpbte 3BL2xlkdkzdcGNvcOhHxIIvGdY/sheAA0Bo4+wxfHv/0P+vhRPMVLqAaeK6Sr6GYMBfI hhSkrmp5RHtpZZjx1ufINfG3YrJFtLgpVdCYOa1azySIsxQRbBYdiODXfb/7EddrZRaH novyuSUnJ4kme6yWGP/OfLDzKWl8z84ubXueazBKc0tP6ntz8mpdQDF3fEmwv63yBwlW DwoA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id uo37-20020a170907cc2500b00886b18c2fabsi536067ejc.24.2023.02.15.18.32.29; Wed, 15 Feb 2023 18:32:51 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229595AbjBPC0r (ORCPT + 99 others); Wed, 15 Feb 2023 21:26:47 -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 X-Spam-Status: No, score=0.9 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_24_48, RDNS_NONE,SPF_HELO_NONE,SPF_NONE autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757953153521688213?= X-GMAIL-MSGID: =?utf-8?q?1757953153521688213?= 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)