Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2084406ybb; Fri, 29 Mar 2019 18:39:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyCLNczKMJqAbn3PY0S7uPRJiq8gYKQbbeKDum8Vrf7jXOr1Ig66YyjKIHu+cp/zQXufrXS X-Received: by 2002:a62:292:: with SMTP id 140mr17568333pfc.206.1553909956705; Fri, 29 Mar 2019 18:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553909956; cv=none; d=google.com; s=arc-20160816; b=rzy+nulXOOfCQHXeRvW9zGQOAeqGrTW9wQHnZ6vwD0QpTSrkK+w1UFqsfYRzw8+tQp AKMGORYGvpa6Tf8B4CWEykrpAFyUT42+8zbAqCJg/hfhHhzvsH0JZejLiJGw149KN7AR 8rzhX9RYzJuVVApzHdFMyrbZThmoTUlEa8dHGCFviGyW86ZdyKHN7tpSa90XHEXppmzh Sj2oqadnZtboTQYpVwqetjgV5mynyx5Lr7zZua6weopEX36cP1Bl+4F4dBMkYg9v2OmI J4yksPBWiUud5fNIYkUpI046JY/IjOEfZSHGGpi6nOSauWuQbdqKYHom4weZ4eknHaZA Q3IA== 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=cU+5cdaN7vWElp2l4u76XaPOgIZUVk3nXjonxeu06p0=; b=YugGmn+DbxmG/IwbrP9QFYXlt4NUkj/eRoIxeOk0GAwinIFJ4cYnMP1AwSuVHyZUzp eyCzgjTWlfXfem1ikrgG9RhKNtEcjlncEWmTQOvXPA2wBuqG60dib12WIvsqYAeMNqvB Wg/QGaSbKYzTJMLDPsbrcEv0LfYVV146ogPhhavyV+dj/UiRrla6tbZqcK/0UZ4s18JB TZSEzSBRQeaRoIhm/difBc5UPyrJdyDFChUWIm5SpYRTB5nPhCa7D3tB5oeAQPItNKvW qyp0k8YrYhDsZMtJifdQOjUNMyDbYaOtssMuM9JTPJr9qBgYzgTU2GlUlZ40JbrdlblD qTBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DZriNhXS; 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 p188si3179927pfp.123.2019.03.29.18.39.01; Fri, 29 Mar 2019 18:39:16 -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=DZriNhXS; 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 S1731595AbfC3BiX (ORCPT + 99 others); Fri, 29 Mar 2019 21:38:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:37492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731450AbfC3BaU (ORCPT ); Fri, 29 Mar 2019 21:30:20 -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 8041B218D8; Sat, 30 Mar 2019 01:30:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553909419; bh=+oGEJGlWZ3n+aKt5lLM28Dlds+Sx0OaLv3xQF9+r2G0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DZriNhXSlYB0oLCtuq6l6XX4HAIWgXzrfGlyBK/XdH3BJljdDm/UZrDdfEf3LFcXp ufoPJ3bmeeS3VjVWV1vwUSmT51Rqavf9DVqTcCclnp2Y5nz4X7p2zFBFyI/hv6mKog V7ZDRsBdpHLyxPMOQwohiC75D+IxS0QKyyjpogKA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christophe Leroy , Kees Cook , Sasha Levin Subject: [PATCH AUTOSEL 4.19 44/57] lkdtm: Add tests for NULL pointer dereference Date: Fri, 29 Mar 2019 21:28:37 -0400 Message-Id: <20190330012854.32212-44-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190330012854.32212-1-sashal@kernel.org> References: <20190330012854.32212-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/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 2154d1bfd18b..07caaa2cfe1e 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 9e513dcfd809..8c3f2e6af256 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