Received: by 10.192.165.148 with SMTP id m20csp3393084imm; Mon, 23 Apr 2018 05:57:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+pk+1fTioI8ujCbIGeL9LI52hlb7X29poygpsfPwsWM6m+szCjlwKQR4MoCS7OEfPjbMFa X-Received: by 2002:a17:902:8601:: with SMTP id f1-v6mr20235790plo.220.1524488263815; Mon, 23 Apr 2018 05:57:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524488263; cv=none; d=google.com; s=arc-20160816; b=bluKFxX/lrdObqv+BzJsWUrCJLbrTSKb5pnOBmgWEp+ZYk4Cdz3Ms8fTD9Ud6fEclw nXGl2ULr5VGI49T1MksA3KjiwLda/5H7pRgr/IygY1ArvmtGMbJqmFW8TInZA8vj4w4G UHMsMDheoPVBGeNqpMGo+DMy7apv1WaxYBkk04oiR4ocQCpXoG9m9dnCTX0xqLOMrcKM kESCsZRNz4W+zqTl8mQEoFP4bAkzcxm2qKWuKYuVhtlCAef4hltFQUZcz3Gl8A/v4kPJ 1mmmEUJIX1rMHEXmPQAZLnevGDt//ltaJlNoaueTm+BvTSMyH+ok/dX50PVMzT8zie+/ JMIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=jwZ+2itaJiX1jytcWxO0WvnASxd1yHLN4hfAbTqc4CE=; b=bob2ubtFRdlNlC1VV+HP+l19Srf4G9w0gVBgaH6mMeI3icD03Xz63oExnH6n4roN/M q0YLFnNA+aZXyDKJyi/VIbW8OULMjFd5dRIY+AMS8Ml74PYhiI/zJ3wh4B3r868izLv8 VWxa9Tzqc1FhAS7U61xPRageohHcY97tGoov4jp8QnACT+IuCyc/czUZJk4FFmpJN0Cz YGFcEgWeC4V9Oi4RY1OMOVQVVaYrm4muxFPkRgYHmx/vS2VVqAlghK4mMQAoNJTpu8o+ v98bcsquF6QC1SHA83VNMHnq+OtLjvGjJdGAIX6RjPs7joLT+b+wxk4wOGa0MU9NL8BF lsWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lhN+OcL1; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6-v6si11717713plo.534.2018.04.23.05.57.29; Mon, 23 Apr 2018 05:57:43 -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=@gmail.com header.s=20161025 header.b=lhN+OcL1; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755315AbeDWM4J (ORCPT + 99 others); Mon, 23 Apr 2018 08:56:09 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:34298 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754919AbeDWMzs (ORCPT ); Mon, 23 Apr 2018 08:55:48 -0400 Received: by mail-io0-f193.google.com with SMTP id d6-v6so18321335iog.1; Mon, 23 Apr 2018 05:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jwZ+2itaJiX1jytcWxO0WvnASxd1yHLN4hfAbTqc4CE=; b=lhN+OcL1F2Dgh23zsQVHXiSS7iOC4CipkT3Y4GezELpb9LU3iH0mYtB1QKB/vUHyNh Ww0eyj1bBJvX/ioc4UjXW9tEDeCeySy7XADVfcw8ohIulvB7zYo31Fv2q9JO0uim8kbm +wvIXmn8e7JR0CDthmcHRpV5qDZ8dnaC29tnIbYKebnTpFGTgKclSqqkXWnfE+Qaxol9 B3Sw2z4YiZ1y4ATKbmkFe30h5jq6AzYzjfSiUR+L8WZuRjRUt+77papgUOTCG+xJNaeb QpOx6XkWPiDvD8zH91U4qYA/RFm+Ls3iRC+8gtLWcdoLXSWYdOiW+wqViWaoil7kZnsQ c9zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jwZ+2itaJiX1jytcWxO0WvnASxd1yHLN4hfAbTqc4CE=; b=Ln7QwourZOSKOJkGeSyAG2zfTzMRAh/XTHWQDd2cM2UqeZxV6a1E6ljlihwyTIRy0I lDgOOeYIvyFGR1/oNU13ZKglynIHwAXW6YVmgwu1t041K0mve40MU1pgo3AW4E0gjyeq lzzB0WuaXN9enWg4xTh7NoFOxf+Jv4pT2s3+FMwHW6Y3RckA79FmTCspAPeP3MMO4LZm 4NAOQQ3p7VB13Ci3lUpqhAULD3gYR7xKogSSwj7cbESSmVOLycXf1hlpZuBQvzz+5jvw La0WhQAvqqkv9xCeBvsE8rEix7AOqfngPBUoob+8iACWsIn8yRtIvWvZREgisioCTYdj k5iw== X-Gm-Message-State: ALQs6tBS1q/b418lXobHgRk4bA65Dz6XKgByqemrm7XMdnx1HKCQ5DMf Q+V8DxGZiujD02mUAVBnBns= X-Received: by 2002:a6b:c002:: with SMTP id q2-v6mr20988824iof.53.1524488147155; Mon, 23 Apr 2018 05:55:47 -0700 (PDT) Received: from Mort.huawei.com (174-23-152-165.slkc.qwest.net. [174.23.152.165]) by smtp.gmail.com with ESMTPSA id n67-v6sm5934417ioe.20.2018.04.23.05.55.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 05:55:46 -0700 (PDT) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: willy@infradead.org, keescook@chromium.org, paul@paul-moore.com, sds@tycho.nsa.gov, mhocko@kernel.org, corbet@lwn.net Cc: labbott@redhat.com, linux-cc=david@fromorbit.com, --cc=rppt@linux.vnet.ibm.com, --security-module@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, igor.stoppa@gmail.com, Igor Stoppa Subject: [PATCH 6/9] lkdtm: crash on overwriting protected pmalloc var Date: Mon, 23 Apr 2018 16:54:55 +0400 Message-Id: <20180423125458.5338-7-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180423125458.5338-1-igor.stoppa@huawei.com> References: <20180423125458.5338-1-igor.stoppa@huawei.com> 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/core.c | 3 +++ drivers/misc/lkdtm/lkdtm.h | 1 + drivers/misc/lkdtm/perms.c | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+) 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/lkdtm.h b/drivers/misc/lkdtm/lkdtm.h index 9e513dcfd809..dcda3ae76ceb 100644 --- a/drivers/misc/lkdtm/lkdtm.h +++ b/drivers/misc/lkdtm/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/perms.c b/drivers/misc/lkdtm/perms.c index 53b85c9d16b8..3c81e59f9d9d 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 = 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