Received: by 10.213.65.68 with SMTP id h4csp784623imn; Tue, 27 Mar 2018 08:43:05 -0700 (PDT) X-Google-Smtp-Source: AG47ELs1i2t2WyuT4YF0YWh/FuhZw2HMA58z98nyXyVFoLGMA/XS9uXkg7CtWb8fhyAwJjNW4sSQ X-Received: by 10.98.73.214 with SMTP id r83mr28522463pfi.76.1522165385114; Tue, 27 Mar 2018 08:43:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522165385; cv=none; d=google.com; s=arc-20160816; b=MZHQQl3IKyflTCfjtKUUXl+gVBDTK7iYjoyzG1hkOFhpxc/3aDgnDSCRkeLCue7feM YzamOGxz7EllIq2zDgsct41OwGePDrA+EKtKo2z20k4XcO0rwxhawLMchgRBUsUb3ZPH UlGVvL9MGD7TKFyGzVpet2Ii+e6AE+28rGY+uXGeRjtSAGQo9R8wxnz7zUJt5DlFZEc3 b9n47zH6zpzAGpaG23Wptf4MPy1yGUZH8FBPNSFIeyHunEMT6l+e9NarkVGtcTgF62Nx PWkcJBvdJ3TraHrtPMOGDeSP8IlLA/UleyrYUisSAsh+VEEup5J+q/E4fe7CL+oaBtWS 4JyA== 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=Ag1Atgnn0TdpM19/OWk9ZZoQ4A335k5sZgMog3Xy/y0=; b=jeD2O2fHbKcB2J8snH1FagTuNH1hfTJo3B0sLrII4ez3raBTwAOYlfCyc5oXZLnDqz VW7fAz9pnQ4lM8aGEoqVQLBctaqKwm1sGu/0Al3P/V49pG3uevAfjRMayWajCIlWpJZV bi4WUX09TZc449vQBFSg9uBtvLNa0tf8kpwj04n7hrAmj3RNOWk5WEztfriJ5nUf0BRr lCXJF8PUcEry6c1WE1kHQIr4EyHH+p6OLanX0vAXQWA1fMhiiIht7nzDUUDDs4HOn+Yv ZWO8SpUE2VaIDytYfHnHlzuspvBd3uuL6S0TCEJmM5WZvHfI38PXBxHajbpDD5CrnREC Fgig== 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 s9-v6si1506931plr.42.2018.03.27.08.42.50; Tue, 27 Mar 2018 08:43:05 -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; 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 S1752640AbeC0Pl7 (ORCPT + 99 others); Tue, 27 Mar 2018 11:41:59 -0400 Received: from lhrrgout.huawei.com ([194.213.3.17]:30951 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752088AbeC0Pl6 (ORCPT ); Tue, 27 Mar 2018 11:41:58 -0400 Received: from LHREML713-CAH.china.huawei.com (unknown [172.18.7.107]) by Forcepoint Email with ESMTP id 335D74FDC6AF; Tue, 27 Mar 2018 16:41:55 +0100 (IST) Received: from localhost.localdomain (10.122.225.51) by smtpsuk.huawei.com (10.201.108.36) with Microsoft SMTP Server (TLS) id 14.3.382.0; Tue, 27 Mar 2018 16:41:46 +0100 From: Igor Stoppa To: , , CC: , , , , , , , , Igor Stoppa Subject: [PATCH 5/6] lkdtm: crash on overwriting protected pmalloc var Date: Tue, 27 Mar 2018 18:37:41 +0300 Message-ID: <20180327153742.17328-6-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180327153742.17328-1-igor.stoppa@huawei.com> References: <20180327153742.17328-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 | 25 +++++++++++++++++++++++++ 3 files changed, 29 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..4660ff0bfa44 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,30 @@ void lkdtm_WRITE_RO_AFTER_INIT(void) *ptr ^= 0xabcd1234; } +#ifdef CONFIG_PROTECTABLE_MEMORY +void lkdtm_WRITE_RO_PMALLOC(void) +{ + struct pmalloc_pool *pool; + int *i; + + pool = pmalloc_create_pool(); + if (WARN(!pool, "Failed preparing pool for pmalloc test.")) + return; + + i = (int *)pmalloc(pool, sizeof(int)); + if (WARN(!i, "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