Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2084007ybb; Fri, 29 Mar 2019 18:38:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxM7DHvauyE/fxuYD+ImEpuebXKT1AWYoZEtPYRELECkPFlG7sKjzjFFP421ngtsq4mNNG0 X-Received: by 2002:a62:75d7:: with SMTP id q206mr26713955pfc.213.1553909910859; Fri, 29 Mar 2019 18:38:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553909910; cv=none; d=google.com; s=arc-20160816; b=UQcNIjwH9fc/yTFsNtp72rVGmVNXtF3+xBtvUL0cQcK4OvBo8zJWO4jl/N22joIytW aUTN3Qye2bt+lXrWzFsa+6B5yJSI+Zk9fQwRMKMBtMZi1765cjltBvtqbLISu0wn4x2F ZZAwHAUg6/0X60hYsglpGG4x9qvn3dkDphIzORVKUBVpA66QTweAU6UUiBkQodmlZn7t a2Tjzz8SQipOxfHtxEbSlWdJNAR8eFd7ueFY1ahv9AHGitM1LT0EpylftO3Aekv5Wf6J bf2H0kBEv/VkXfwtVdlINqcgd/jNy6gadUCsPnayLVj44S6t8xhz7YGywBdpQ+HrtABp AfMQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rDy4SVVi3Tm0GUFk81LEabTRsZ6crhSI107k+cCJQ+Q=; b=S3agsYFLIz9IS2iUmZVK8C2Cr5YUGQwtcypzHd8f/gT1OZYcHqGv1rbeXks8nqtdCM T+FLXjIlmPIPhwcqzS1/YD1h6yN2ytIXsfOhCMD9+OIWvkvixDVMG2lusKY9rQqgu7lh AEeTLuxiuaFjHIJPqi9SxzfLbRjSkmZ0RXaSVyzmUf93KZxDw+Z4C84Ww9Obtnkx8qj6 5McDpS0EAYgJSy/OUPHazElX1ZcR4zG0GuXjZwvpfyqRgsK41Dy3Oiu0Eb5Q53FwQxbu U0XxgR6Vg2L4E5TWv08vytnPDGimYXecdT5rOwk31XWthW3caEuH+QrBTPmUb16fu3HD H7wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2BYZ4CHq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2si3104698pgp.444.2019.03.29.18.38.15; Fri, 29 Mar 2019 18:38:30 -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=2BYZ4CHq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731930AbfC3BbP (ORCPT + 99 others); Fri, 29 Mar 2019 21:31:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:38656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731853AbfC3BbM (ORCPT ); Fri, 29 Mar 2019 21:31:12 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9E875218D9; Sat, 30 Mar 2019 01:31:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553909471; bh=UnqTKYylofMuqcN0OABGUyiWSKXqfBOyL39IujjBkv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2BYZ4CHqganRFjy4DAPfVDMen5IBBmLF7ZPUQ+Q7wHzjYe79716OzD8QxURh9oZHd 6fFrIV2YqNWA2a1hg6Jcs1m/m7uwFz587nUP8X4f4Fy6rMSamHn1R0nHjK+AcM04Z/ iQmXLFlAawodAPqqrRuV30Yw1hhqLsvLFBd8DVDE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christophe Leroy , Kees Cook , Sasha Levin Subject: [PATCH AUTOSEL 4.14 27/37] lkdtm: Add tests for NULL pointer dereference Date: Fri, 29 Mar 2019 21:30:10 -0400 Message-Id: <20190330013020.379-27-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190330013020.379-1-sashal@kernel.org> References: <20190330013020.379-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe Leroy [ 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.h | 2 ++ drivers/misc/lkdtm_core.c | 2 ++ drivers/misc/lkdtm_perms.c | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/drivers/misc/lkdtm.h b/drivers/misc/lkdtm.h index 687a0dbbe199..614612325332 100644 --- a/drivers/misc/lkdtm.h +++ b/drivers/misc/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_core.c b/drivers/misc/lkdtm_core.c index 981b3ef71e47..199271708aed 100644 --- a/drivers/misc/lkdtm_core.c +++ b/drivers/misc/lkdtm_core.c @@ -220,7 +220,9 @@ 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_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