Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp890517yba; Thu, 18 Apr 2019 11:16:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCRkvUTRlgJuSnTNKioxcTatXQ2SN1GTdOy4oiNgEY/hOxi5xxoOuoVzbIgAo/vuJgND7Q X-Received: by 2002:a63:100e:: with SMTP id f14mr56080910pgl.192.1555611407670; Thu, 18 Apr 2019 11:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555611407; cv=none; d=google.com; s=arc-20160816; b=IofNVJ+nrocPtl2TL5bDFyCahvXD9Og9IyvrH5EltYdJSxU7oecbKWVIAtc+ioG4ZN yUbPxJoKN4FRlJpY9tRAhjvTkpLWBzyoqv/nCMj6cV+ED0mRqhUWI8oAeBB7Y3WRjsyJ 8LkyWEBxTSg6zk7FUN+38ca2L8XiSYMonNNEkRSE6etnspG9UR2/7ezN/ABIWrmWnN90 fTmW1tezefglbfRCot6RqhEBtT/Jigua3klELI5f0zFT088L9RYpHpELD7zXhVxYPj/k OOJ+3V5VK+XodRwmPUTGGvgeW4RPMQjq0nLjmNI85KP9Emmb8H3EX06hy3ElzUi9i1ak mmtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZlU3N7M3gh4/GDGT0+3ENifOuMN/VbVz9anEpWHsJT4=; b=UqebZtYhNeHKgCQTL2l5lOVTVenN2cs5Qnfn1kCXmHt5gqfM57DhRN20jAjZzVXS5l JODqN1mJaGC6brny0rgJbvK/msu+LUm3jJvwYS8EsG/GS2mYcknMNzEPxwjXJAbPv96C qxKcBSyoNtwNHFZjHHR/gjg5G3xSwMeKsEqQLWe5nuWM3YEKIEeyNbm25oZ3xRAr82a0 Q21yaGqDcR0WdHDjMyM38SQj9xYRjb+L1IqUbpWG8nqea7GV/Dx8VynoQkUSlgw5caWL EUj/6m2HqlT8haOU25Pv5BBaAGwCnLj6De8xWDjse04jTg9MOLcAqlf95l468gJpPRp7 N2cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pe1cpmb2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si2811774pfh.205.2019.04.18.11.16.33; Thu, 18 Apr 2019 11:16:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pe1cpmb2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404228AbfDRSNm (ORCPT + 99 others); Thu, 18 Apr 2019 14:13:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:46148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404429AbfDRSNX (ORCPT ); Thu, 18 Apr 2019 14:13:23 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3BE2E20675; Thu, 18 Apr 2019 18:13:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555611202; bh=as/nN4T3Fu9wls1bro8220TLPnR136JubvVNVCILYBc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pe1cpmb2MhsAw4em8vTLSBqKmulLHvF5FTxGVI5W60pQEDwxaIOPbE7AAgZ/PZR1k Fkd30K+cfD00n5mpljXApf20fVeeT6/oIy53Ms2jviDdw136r7Y+I0UmOUjbA6HuWT l++tUdTtxE0j9J+6xB9jrYfHvJaNkJZkNjX2NvAE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe Leroy , Kees Cook , Sasha Levin Subject: [PATCH 5.0 69/93] lkdtm: Add tests for NULL pointer dereference Date: Thu, 18 Apr 2019 19:57:47 +0200 Message-Id: <20190418160444.212809259@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160436.781762249@linuxfoundation.org> References: <20190418160436.781762249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 59a12205d3c32aee4c13ca36889fdf7cfed31126 ] Introduce lkdtm tests for NULL pointer dereference: check access or exec at NULL address, since these errors tend to be reported differently from the general fault error text. For example from x86: pr_alert("BUG: unable to handle kernel %s at %px\n", address < PAGE_SIZE ? "NULL pointer dereference" : "paging request", (void *)address); Signed-off-by: Christophe Leroy Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- drivers/misc/lkdtm/core.c | 2 ++ drivers/misc/lkdtm/lkdtm.h | 2 ++ drivers/misc/lkdtm/perms.c | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c index 2837dc77478e..f0f9eb30bd2b 100644 --- a/drivers/misc/lkdtm/core.c +++ b/drivers/misc/lkdtm/core.c @@ -152,7 +152,9 @@ static const struct crashtype crashtypes[] = { CRASHTYPE(EXEC_VMALLOC), CRASHTYPE(EXEC_RODATA), CRASHTYPE(EXEC_USERSPACE), + CRASHTYPE(EXEC_NULL), CRASHTYPE(ACCESS_USERSPACE), + CRASHTYPE(ACCESS_NULL), CRASHTYPE(WRITE_RO), CRASHTYPE(WRITE_RO_AFTER_INIT), CRASHTYPE(WRITE_KERN), diff --git a/drivers/misc/lkdtm/lkdtm.h b/drivers/misc/lkdtm/lkdtm.h index 3c6fd327e166..b69ee004a3f7 100644 --- a/drivers/misc/lkdtm/lkdtm.h +++ b/drivers/misc/lkdtm/lkdtm.h @@ -45,7 +45,9 @@ void lkdtm_EXEC_KMALLOC(void); void lkdtm_EXEC_VMALLOC(void); void lkdtm_EXEC_RODATA(void); void lkdtm_EXEC_USERSPACE(void); +void lkdtm_EXEC_NULL(void); void lkdtm_ACCESS_USERSPACE(void); +void lkdtm_ACCESS_NULL(void); /* lkdtm_refcount.c */ void lkdtm_REFCOUNT_INC_OVERFLOW(void); diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c index fa54add6375a..62f76d506f04 100644 --- a/drivers/misc/lkdtm/perms.c +++ b/drivers/misc/lkdtm/perms.c @@ -164,6 +164,11 @@ void lkdtm_EXEC_USERSPACE(void) vm_munmap(user_addr, PAGE_SIZE); } +void lkdtm_EXEC_NULL(void) +{ + execute_location(NULL, CODE_AS_IS); +} + void lkdtm_ACCESS_USERSPACE(void) { unsigned long user_addr, tmp = 0; @@ -195,6 +200,19 @@ void lkdtm_ACCESS_USERSPACE(void) vm_munmap(user_addr, PAGE_SIZE); } +void lkdtm_ACCESS_NULL(void) +{ + unsigned long tmp; + unsigned long *ptr = (unsigned long *)NULL; + + pr_info("attempting bad read at %px\n", ptr); + tmp = *ptr; + tmp += 0xc0dec0de; + + pr_info("attempting bad write at %px\n", ptr); + *ptr = tmp; +} + void __init lkdtm_perms_init(void) { /* Make sure we can write to __ro_after_init values during __init */ -- 2.19.1