Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1862499pxm; Fri, 4 Mar 2022 05:09:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4/TSyNPxofECSvSRQKaptC49aGUt11gLt4XSrPaWghfJ8aGA7e5U7P6qnFhLfeGBdx5o4 X-Received: by 2002:a17:907:60cc:b0:6da:9616:ecec with SMTP id hv12-20020a17090760cc00b006da9616ececmr6089810ejc.298.1646399358877; Fri, 04 Mar 2022 05:09:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646399358; cv=none; d=google.com; s=arc-20160816; b=0WEM6GCb/rfsoZi28NIv1XbZfuAGkLaMMDePILTp03t/zaMTk2g14LnzPAszzLwliL 2Jb5XE2AtQL0s37qRrGoUjOg9NsBDz5FiFDCgoNc/yH95BnRUwRzBPLPkxLGs/ABIkZZ 0h2n/iQSfo+rgZ2mA9f8Ag4BgHnqWhb6gD5kYciPNO60Gi2kNlsuGNrUJohKJlJtnH57 k7C/kqlwUyJPRwAJ4+fGQ5V/Owo6JrvvzBHFmdeDLPVthadL8JzRahaySFN+xwlfUrvM ONsiRT8gbfhg0ki49TIp2t/COo7OpUXuv9ETqoqC3eE5jnUqBPljggNHI4AIWr0M/qya fdwQ== 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:date :subject:cc:to:from:message-id:dkim-signature; bh=lWyaumg3DAV6K6mwQJGodMoZXgiEDM6A7q29hCzQNEM=; b=uHt4ryY7JbVI1eYZ7f3JZgVfNP1wZ4wy3KSlhneK7yJyq210EpjknNMUL85XmkbqV6 IWsm8D7WYcazmVvTazn2SbSIemjsaQOnDehcw/CeVBDCGR/jWpoOiTaIXFkxzqSJHwZc Zf/FslgWlVLZJK7F0HJTB/2jMwJa4m6yzxav6T7x8XrpKsSj2RgpMrFgnqz3SAmgaDwQ o1tZdTPmi7kB0V/YSGr+v9eq24yXowgJU+bB6A/qCqx7c9U5AqJ/G5/HsGhBByMYgK1L Hi720IWbiEwWNx7Ad/+B2xddfA9JKA/g10mXiCz/yp79klfKh9Z7TGTQHo786cOZ6p5A /LOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=ZxzzA7kk; 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=foxmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd5-20020a1709069b8500b006a744d0cdeesi3377272ejc.875.2022.03.04.05.08.51; Fri, 04 Mar 2022 05:09:18 -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; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=ZxzzA7kk; 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=foxmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234560AbiCDKbp (ORCPT + 99 others); Fri, 4 Mar 2022 05:31:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234383AbiCDKbo (ORCPT ); Fri, 4 Mar 2022 05:31:44 -0500 Received: from out162-62-57-87.mail.qq.com (out162-62-57-87.mail.qq.com [162.62.57.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7169716BFAC for ; Fri, 4 Mar 2022 02:30:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1646389850; bh=lWyaumg3DAV6K6mwQJGodMoZXgiEDM6A7q29hCzQNEM=; h=From:To:Cc:Subject:Date; b=ZxzzA7kk36YTYHZb6KJqWR4mfTA7eV2ol13wKwIKW9cW6/jb7ww+qIVdlHfFMxkMB rWTwb+NdPwNVAlZeURtx9r07l5Kautyv6Zdr6Seyw+QuQ2GZ1KsKykNffIu3fycCYc ds7eM5+fpJ80tnodLyI7DHouFenvykSt+ZGY9KUw= Received: from localhost.localdomain ([218.197.153.188]) by newxmesmtplogicsvrsza9.qq.com (NewEsmtp) with SMTP id 7AF34219; Fri, 04 Mar 2022 18:30:47 +0800 X-QQ-mid: xmsmtpt1646389847tppgzcpa0 Message-ID: X-QQ-XMAILINFO: OKkKo7I1HxIe9JbE8Y6zN8gmAhbqYsL8XRbKtldCSvGqt/3CKmVFBJ9ln5uZzs Yi+pXIZ6FswivyrvBbAxbTXGiMBY+ReqstIi1N8etvOmUAOuaTbPzcb/gCdod+tI28/osT+GXToa 5uzUnwU8RGUwSNS+w7O+V/UPOzmSeMEEZJJ3KPCFnC0xOjZFZjtknX6mk4zwJ4hteofgg9sGDCCS +ukl6JoWDID8nwQlN86TPuHQVQ2cZeD9SyUKXyhU51KHjeexKxwB8LaZOrDY6c98WIYwNlS2OjeU gI26ew9ON5tTnACbAUs1Fi8Yn5/TRqDFqCRhCp2JEZqiJav+Pl8rrpL4LBIAhbAbV0bGLNOHS/3L qrsWEAykVxZSIwRECDsnQCtyJUEHZM1rcYnxrsAd+Sneqo6ZoTskzCA1LKWxZ3egNSr9p7/fj6Jb 6X/0aHHJ+sR+ssPplqiGqQsx97ijxQ3dPa4LNtWUs11UnQc2E1gznsH+mT43j6vNXElo49em/+6o b0QIk2cDvoZOyRh51zlTjJ8qhvL6zCZV5lWZPza+IZrwNiLot0tavUxRkrP24hLtwPMVpjfKrooI 5usuWvxIGj8PsY29tdsZxl3By4y+tIl2SubvuH6Vde4mWI3Sko7KyQ8D5hxcb/JwurJxnH/gpKFh fOKftAJX6IXI7vendijqYvnd8+vR+24qMqLyjJ1YZe7alGAopTilLHRbAEq9ylCve8b3QPkf4s+m X7HxpzT9UnPd56qwE/hieFEAQIUSkna+sC0KC6dkMAXh9i5wVwpPd5ySeajuwGkC93ULvE+oZM/I vvJ9BmlRpLmhUm8Wppj9hV/gvHX14CooMhnnVO/3CW0d5GdiA6vEF3st66sPaEm1MR5tEDGqQOZx hnpVowlpDQ8RsfzmTYpy/iD5Ur1TbiX4VqkZKbOre3HH8v2K8KyO0AhyUeiuYAjAmhxMvtTGPj From: xkernel.wang@foxmail.com To: keescook@chromium.org Cc: arnd@arndb.de, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Xiaoke Wang Subject: [PATCH] lkdtm: add checks for the return of memory allocation functions Date: Fri, 4 Mar 2022 18:30:35 +0800 X-OQ-MSGID: <20220304103035.5389-1-xkernel.wang@foxmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HELO_DYNAMIC_IPADDR,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 From: Xiaoke Wang kmalloc() and vmalloc() are all memory allocation functions which can return NULL when some internal errors happen. So it is better to check the return value of it for better testing the preset purpose. Signed-off-by: Xiaoke Wang --- drivers/misc/lkdtm/perms.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c index 2dede2e..3eabc6f 100644 --- a/drivers/misc/lkdtm/perms.c +++ b/drivers/misc/lkdtm/perms.c @@ -138,6 +138,10 @@ void lkdtm_EXEC_STACK(void) void lkdtm_EXEC_KMALLOC(void) { u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL); + if (!kmalloc_area) { + pr_warn("Failed to allocate memory\n"); + return; + } execute_location(kmalloc_area, CODE_WRITE); kfree(kmalloc_area); } @@ -145,6 +149,10 @@ void lkdtm_EXEC_KMALLOC(void) void lkdtm_EXEC_VMALLOC(void) { u32 *vmalloc_area = vmalloc(EXEC_SIZE); + if (!vmalloc_area) { + pr_warn("Failed to allocate memory\n"); + return; + } execute_location(vmalloc_area, CODE_WRITE); vfree(vmalloc_area); } --