From patchwork Fri Apr 27 21:55:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffrey Hugo X-Patchwork-Id: 10369921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D93BA601BE for ; Fri, 27 Apr 2018 21:56:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C71B128563 for ; Fri, 27 Apr 2018 21:56:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB68F29515; Fri, 27 Apr 2018 21:56:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4F11028563 for ; Fri, 27 Apr 2018 21:56:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=nx9NUrP59acY60bfA5OaONcbCLJe38qj7bG1o6Wwi60=; b=bMh Ey3/xnj0Lc1dbBHJQnMOvkGqluQYzGkWeNY5p1rPVfxyEvhwTGwCmsXa/I5PVV5feG3Ttd7/3jhMk QFPW37/rJbt9bgJP8j4bCPfL8MhH/mgSnYSJGoQG1jdA68w4Nl4IZ8+jkKl9yiCpE2q2SvDBQVVeX HAvmD5cWo3B6Zym595wUJNFGd/+g9K5GJ/duWl2Nrl5Cwql5MDELM50+8KiaDf/Delb4FQlFQ6kaD lX1TUkGCP0SA7Ga6yRSVHJ+qe7RFTDH0POdJIH95nLHFzqBHsvwxBOCsr+sBojuf7RTTLz1l+HmNP m5wMH5DAkOOmJa+Kz4H0zwg3YRPj3yw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fCBLm-0003xY-VS; Fri, 27 Apr 2018 21:56:18 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fCBLi-0003wG-He for linux-arm-kernel@lists.infradead.org; Fri, 27 Apr 2018 21:56:16 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id F396060767; Fri, 27 Apr 2018 21:56:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1524866164; bh=pR806uDaMD5BP2/6mztb0nWrdDF1W4ySaugMHjrUsCc=; h=From:To:Cc:Subject:Date:From; b=SrPoM1bLV1dsA218ldyw4U+UKPlOIv9nk/pXNymbNZXW1s0HrwfnMgVhH7qTdNCji vlcfzHTIZAnValBOFf99IiTr4PE9mfVLt+zrFikdd1ZqWKXFZUzudce7tCwRApS1hK 3+q9e+Aj0BXkksKO7Esc32ftzC8FKWWmwX2OrgRI= Received: from jhugo-perf-lnx.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: jhugo@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 936CC60452; Fri, 27 Apr 2018 21:56:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1524866162; bh=pR806uDaMD5BP2/6mztb0nWrdDF1W4ySaugMHjrUsCc=; h=From:To:Cc:Subject:Date:From; b=FI4UjuEtg35mZaXc3+h0pVK+Ztxw6V7roIb7Ww5QsigCmvQYC+ktkvKLDAGe0aoVf iiZ46CZkdlGrfUiQdXltfAfB40Id2i/05W/nr/xTb+fAkRoUuJtvt/s301PgMHTGtS U9hj8kDNiRqn3VUCENEoLK2Ub484ShGeDeh5PgKU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 936CC60452 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=jhugo@codeaurora.org From: Jeffrey Hugo To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] init: Fix false positives in W+X checking Date: Fri, 27 Apr 2018 15:55:45 -0600 Message-Id: <1524866145-20337-1-git-send-email-jhugo@codeaurora.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180427_145614_639653_35F8CC12 X-CRM114-Status: GOOD ( 13.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Kees Cook , Ard Biesheuvel , Peter Zijlstra , Catalin Marinas , Timur Tabi , Will Deacon , Jan Glauber , Jeffrey Hugo , Thomas Gleixner , Andrew Morton , Laura Abbott , Stephen Smalley , Ingo Molnar MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP load_module() creates W+X mappings via __vmalloc_node_range() (from layout_and_allocate()->move_module()->module_alloc()) by using PAGE_KERNEL_EXEC. These mappings are later cleaned up via "call_rcu_sched(&freeinit->rcu, do_free_init)" from do_init_module(). This is a problem because call_rcu_sched() queues work, which can be run after debug_checkwx() is run, resulting in a race condition. If hit, the race results in a nasty splat about insecure W+X mappings, which results in a poor user experience as these are not the mappings that debug_checkwx() is intended to catch. This issue is observed on multiple arm64 platforms, and has been artificially triggered on an x86 platform. Address the race by flushing the queued work before running the arch-defined mark_rodata_ro() which then calls debug_checkwx(). Reported-by: Timur Tabi Reported-by: Jan Glauber Fixes: e1a58320a38d ("x86/mm: Warn on W^X mappings") Signed-off-by: Jeffrey Hugo Acked-by: Kees Cook Acked-by: Ingo Molnar Acked-by: Will Deacon --- v1: -was "arm64: mm: Fix false positives in W+X checking" (see [1]) -moved to common code based on review and confirmation of issue on x86 [1] http://lists.infradead.org/pipermail/linux-arm-kernel/2018-April/573776.html init/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/init/main.c b/init/main.c index b795aa3..499d957 100644 --- a/init/main.c +++ b/init/main.c @@ -1034,6 +1034,13 @@ static int __init set_debug_rodata(char *str) static void mark_readonly(void) { if (rodata_enabled) { + /* + * load_module() results in W+X mappings, which are cleaned up + * with call_rcu_sched(). Let's make sure that queued work is + * flushed so that we don't hit false positives looking for + * insecure pages which are W+X. + */ + rcu_barrier_sched(); mark_rodata_ro(); rodata_test(); } else