Received: by 10.223.185.116 with SMTP id b49csp4073407wrg; Tue, 6 Mar 2018 09:22:04 -0800 (PST) X-Google-Smtp-Source: AG47ELtWHyBGoAwGNxKVcmSuRlnhj3hnPvKm59LQsbbD3VmckUhEtN5SrS4DPErAmN53xOIcqE6y X-Received: by 10.98.32.28 with SMTP id g28mr19772816pfg.182.1520356924187; Tue, 06 Mar 2018 09:22:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520356924; cv=none; d=google.com; s=arc-20160816; b=pECsjpMMnwlzUnA1UjBRoZMUdlntaVatfzoSV2M18iGpD71eaWWM2jvDTH/pbo5SPf SIycXKrWR8GHb1C83URp/+tZPnRFawNyGd/qkx/TwqOYmb7DBZmruNo2ZALNMGA2HQE7 KVI7TMHsd1vxirm8NFM23keo5t77cKAssxEmrbu3ActLECrRgybrU8aYETqTn6D7o+El +7qDHjiJq5KD8bQT9Uhwcw/Xtfz7GodCkkQwna8LN9cYHwJxu9OsRhCd401nek3/We+c s5V0KsWldpdM75iUkxk+i2w9CNxrfzQ7XU///+hwzeTs3D9ZM2/W8PymZwat81FL7tXR J36g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=4ZownzUDtrY97MLskUPQVnSjwTn4V6B6F7ArBGM/nUM=; b=zkoPjuP0VgEZCKJFUlfgTgN4Zqe8h7FZ+deQt8e6gLOTBal6p2VkmwuT2SaWj8Fkga sxAjx4v564KV5EibjDZDmLhmX8w8Ybm8oKX3ER09II4OTLk3Yw7AUmRYyQBXtscDjGgv LPmtuRRraijCUGX+xheKmgyMJ/8oafA+xKLzDyRl9kV9jNDZEpGQ4G37PPrsuUpY/KP8 I8f8/XCS8MozUE9htvyera2mMEo4hInfmoN4e9MLUIXlnwv89XF4QxME1zrQbApBQ7rb ZfMaXorTYHpU4BI8xdAdmbqBMQOw7+fVIybi0WP6rfb7DrxDkl4qyabG/fTOlMH+tmP6 ta5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jTDB8pEL; 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 b5si12237067pfc.337.2018.03.06.09.21.49; Tue, 06 Mar 2018 09:22:04 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jTDB8pEL; 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 S1753965AbeCFRUL (ORCPT + 99 others); Tue, 6 Mar 2018 12:20:11 -0500 Received: from mail-pl0-f66.google.com ([209.85.160.66]:35068 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753930AbeCFRUI (ORCPT ); Tue, 6 Mar 2018 12:20:08 -0500 Received: by mail-pl0-f66.google.com with SMTP id w22-v6so1027185pll.2; Tue, 06 Mar 2018 09:20:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=4ZownzUDtrY97MLskUPQVnSjwTn4V6B6F7ArBGM/nUM=; b=jTDB8pELVWJJ/6ixowzbpYMJfBjuiYxJRY+8F6CjQd2TKdcRbLlyxobIZwNgzGCdLY SLGELKVj/2S3xPMRDzrhcc02ong3Or9wKHEP8kvYG2ortLlWanSqDy62wRdj4gcEOYog ALfnKTuU+gvvkDnDc4w4izeDJEZWvl3ZYsxULpWQ55yhK4DhdNmojrmFj6pxFTJv+dnX J4kszQIRi/64anYq+B3T8lFxFHxWoEVFwZxcYfMibmtv87LRQqawhIvKHTgT6HRFuIgR 1bRYZVuPXPzDLn1X8F0N6n9BWspZrhkvbTGpnNcC0yuAwMP5WOdtWqw4/3fANuYZzun3 8mYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=4ZownzUDtrY97MLskUPQVnSjwTn4V6B6F7ArBGM/nUM=; b=Myu9gu9W9HbDGhgLWAT3Nxea6LDoaV46+Hi+Is9sZ+kKQxPGNsYlPk2j0Hx+Hshzy5 tXPpBkvUgbRz7Wx00qBWgX7r1IDJ7Ej5ubv7dQbIshHjhzjdeWklDbV+Dc4Aiz3l+XzN 8q0qlDFfXSVgnLs2+B653qHm8LsadIhjjL//4J6bRqFZ7Y0Q9duwWVpFWm+HETFWcil4 I6/YAqqlemdj7kwsZrDDomwP7aeOtlWcQOIGnXgbXqVCJa9hn5GkDw9lOhADubMbuZC9 UDr3e4Z/2y2wx9qZXNZBCc/+ZMU64nZUwTwaaslxnFi7G7xqTfWj0ZFj+pD0P842H/er rpgw== X-Gm-Message-State: APf1xPBuQHnhPUcpmbhKMiQOs2ZV1i/n6t/wOPvCzjRUfo7qcxyjd5GP iUB1lH8uu6NXuzsNyy+LKOs= X-Received: by 2002:a17:902:b58d:: with SMTP id a13-v6mr17772630pls.123.1520356808309; Tue, 06 Mar 2018 09:20:08 -0800 (PST) Received: from JF-EN-C02V905BHTDF.tld ([12.111.169.54]) by smtp.gmail.com with ESMTPSA id a28sm31461121pfe.70.2018.03.06.09.20.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Mar 2018 09:20:07 -0800 (PST) Subject: Re: [PATCH 6/7] lkdtm: crash on overwriting protected pmalloc var To: Igor Stoppa , david@fromorbit.com, willy@infradead.org, keescook@chromium.org, mhocko@kernel.org Cc: labbott@redhat.com, linux-security-module@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com References: <20180228200620.30026-1-igor.stoppa@huawei.com> <20180228200620.30026-7-igor.stoppa@huawei.com> From: J Freyensee Message-ID: <1723ee8d-c89e-0704-c2c3-254eda39dc8b@gmail.com> Date: Tue, 6 Mar 2018 09:20:04 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180228200620.30026-7-igor.stoppa@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/28/18 12:06 PM, Igor Stoppa wrote: > 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); Does this need some sort of #ifdef too? > 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; OK, now I'm on the right version of this patch series, same comment applies.  I don't get the local *i assignment at the end of the function, but seems harmless. Except the two minor comments, otherwise, Reviewed-by: Jay Freyensee > +} > +#endif > + > void lkdtm_WRITE_KERN(void) > { > size_t size;