Received: by 10.223.185.116 with SMTP id b49csp6604155wrg; Wed, 28 Feb 2018 12:12:24 -0800 (PST) X-Google-Smtp-Source: AH8x224I/mK+b081RVqvwT5DuLNXMWV6zPOls8OKk4LwcNMzAMs11izOm3eNudAmkEUc7iGYhqoy X-Received: by 10.101.87.199 with SMTP id q7mr15364639pgr.215.1519848744361; Wed, 28 Feb 2018 12:12:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519848744; cv=none; d=google.com; s=arc-20160816; b=VDAZQ6wbB2tv1YvHHhO74ZjRHjM/rgUDffpe9Xjh6MC15bmnBe1L5GoHM/T6gz1aAQ eP2IMTDnfiue63+1eHVAYRSkfmsieUho/+3s9d9y3iK9uAdx53MTVuO5YCx9CWyJVt56 wjhhCbhjwDiDRywiPeIWZLAGgu6Ytc1MjCsXPimeQaefISgdpvL00qTUxU6BZpd0RDrn Ub/B/NPN9NwcXEn0afE9mhzzKDNgM1QFc4XFDXR85J6CY9gFWsEX0i10wqpJ1+BWG6dJ wCir6Jp8AuH86iP0LTK6LoNNxWeVxMMO/LhCJ+frTDX0dGFb0Iif02Sj1i+CcqX7pVIK HZwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=r+/dQbGqp28pibuoRjnpcP730sLxUhZuApp/+iHgoXc=; b=DGc6KxhyCO7PPbXQNh0qmxEJCJQHszQv6sNtzM41UO+BpjoJ7OPMsvbMsw9cYxpJZq T+e2Jro6TQSK/TIXeqOTP6cDUEYJek0H9yR/a/a2eqB0MlGcPtzTKaFX1ccKJZsd3HkH 7fdY9wLwsOsLZL9juGcrJ0oIJP0NV2GFw/ZCJavqdUq6aTo45bhUkKWTAuwcuhOWnk9I oEQ+cCZMGNve9CybRDbnVql8QL2GM+v4y1K/5UKKTuNROxvjCec9VGygwuexPYbA/fqx /3HSv8UjEmxuDP9tZhLAfeJzauqrK7mvMMAzAIQUaojSdpA5QlbjlXEMNDhfT0q75mEY mYzA== ARC-Authentication-Results: i=1; mx.google.com; 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 v4-v6si1732104plp.746.2018.02.28.12.12.09; Wed, 28 Feb 2018 12:12:24 -0800 (PST) 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; 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 S934442AbeB1ULb (ORCPT + 99 others); Wed, 28 Feb 2018 15:11:31 -0500 Received: from lhrrgout.huawei.com ([194.213.3.17]:27899 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934011AbeB1UL3 (ORCPT ); Wed, 28 Feb 2018 15:11:29 -0500 Received: from LHREML712-CAH.china.huawei.com (unknown [172.18.7.106]) by Forcepoint Email with ESMTP id C9484E9A5449F; Wed, 28 Feb 2018 20:11:26 +0000 (GMT) Received: from localhost.localdomain (10.122.225.51) by smtpsuk.huawei.com (10.201.108.35) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 28 Feb 2018 20:11:22 +0000 From: Igor Stoppa To: , , , CC: , , , , , Igor Stoppa Subject: [PATCH 6/7] lkdtm: crash on overwriting protected pmalloc var Date: Wed, 28 Feb 2018 22:06:19 +0200 Message-ID: <20180228200620.30026-7-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180228200620.30026-1-igor.stoppa@huawei.com> References: <20180228200620.30026-1-igor.stoppa@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.122.225.51] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Verify that pmalloc read-only protection is in place: trying to overwrite a protected variable will crash the kernel. Signed-off-by: Igor Stoppa --- drivers/misc/lkdtm.h | 1 + drivers/misc/lkdtm_core.c | 3 +++ drivers/misc/lkdtm_perms.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/drivers/misc/lkdtm.h b/drivers/misc/lkdtm.h index 9e513dcfd809..dcda3ae76ceb 100644 --- a/drivers/misc/lkdtm.h +++ b/drivers/misc/lkdtm.h @@ -38,6 +38,7 @@ void lkdtm_READ_BUDDY_AFTER_FREE(void); void __init lkdtm_perms_init(void); void lkdtm_WRITE_RO(void); void lkdtm_WRITE_RO_AFTER_INIT(void); +void lkdtm_WRITE_RO_PMALLOC(void); void lkdtm_WRITE_KERN(void); void lkdtm_EXEC_DATA(void); void lkdtm_EXEC_STACK(void); diff --git a/drivers/misc/lkdtm_core.c b/drivers/misc/lkdtm_core.c index 2154d1bfd18b..c9fd42bda6ee 100644 --- a/drivers/misc/lkdtm_core.c +++ b/drivers/misc/lkdtm_core.c @@ -155,6 +155,9 @@ static const struct crashtype crashtypes[] = { CRASHTYPE(ACCESS_USERSPACE), CRASHTYPE(WRITE_RO), CRASHTYPE(WRITE_RO_AFTER_INIT), +#ifdef CONFIG_PROTECTABLE_MEMORY + CRASHTYPE(WRITE_RO_PMALLOC), +#endif CRASHTYPE(WRITE_KERN), CRASHTYPE(REFCOUNT_INC_OVERFLOW), CRASHTYPE(REFCOUNT_ADD_OVERFLOW), diff --git a/drivers/misc/lkdtm_perms.c b/drivers/misc/lkdtm_perms.c index 53b85c9d16b8..0ac9023fd2b0 100644 --- a/drivers/misc/lkdtm_perms.c +++ b/drivers/misc/lkdtm_perms.c @@ -9,6 +9,7 @@ #include #include #include +#include #include /* Whether or not to fill the target memory area with do_nothing(). */ @@ -104,6 +105,33 @@ void lkdtm_WRITE_RO_AFTER_INIT(void) *ptr ^= 0xabcd1234; } +#ifdef CONFIG_PROTECTABLE_MEMORY +void lkdtm_WRITE_RO_PMALLOC(void) +{ + struct gen_pool *pool; + int *i; + + pool = pmalloc_create_pool("pool", 0); + if (unlikely(!pool)) { + pr_info("Failed preparing pool for pmalloc test."); + return; + } + + i = (int *)pmalloc(pool, sizeof(int), GFP_KERNEL); + if (unlikely(!i)) { + pr_info("Failed allocating memory for pmalloc test."); + pmalloc_destroy_pool(pool); + return; + } + + *i = INT_MAX; + pmalloc_protect_pool(pool); + + pr_info("attempting bad pmalloc write at %p\n", i); + *i = 0; +} +#endif + void lkdtm_WRITE_KERN(void) { size_t size; -- 2.14.1