Received: by 10.192.165.148 with SMTP id m20csp1211626imm; Fri, 27 Apr 2018 14:57:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq68l5Vr3DzMRkobg4xBrDIxblE6DwF+jQ5JYqlVRP9tm8B6EYp4nVH1rdAdM6GvpwXhzKS X-Received: by 2002:a63:344c:: with SMTP id b73-v6mr3483553pga.258.1524866266942; Fri, 27 Apr 2018 14:57:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524866266; cv=none; d=google.com; s=arc-20160816; b=01ZirwuprwhA/0LVOu7WhEScLWcWviD7XDHW/zqohQjl5B+VGJllep/lrZ48r6a03U zUxytsH1joxG6NrCUEkyLC7vmKIdioiglMkw23VJpNCtUvyLc10Qjb/lQa5OdOTBVAHT cvAXHegP4ooswUx7K170JaVlbVHSYEJDIxMhX98gwzWItZpWSi0Ske7KpQpDU6fYIVww XcItEZxUniL2hSc5d9Kb5u8uxP+zBtmrDeg3gFl7PY/eRKKa039dnVQ8FZHhMeWM/jbV jaM6aowtJ4gV3DqbXX0yE/VWCCIgkfNN5JKpRuTKT1HxEX2vx0X5Cgw9hVlem/ciRoAu vcmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=6AY8to13rkBTurdi49TsDayCm0ZUIiLQm/qv0mexutk=; b=UXdA0WxNS7ivEhkgTzxFPAmS5n27rg9lQsq5qXtLfo5ClEf5mTADYpVlBFMav32KdX UyjhkVwmmKjV7VORSZykxZPKtRjEVUMlth03yoUhvgfOf3GJvlBRm5/3cpdtsUI9x7ze t4evuEweVbs/g+c8UBi5OVQ7FS0Zp5fEM57xA/094nNYbSp65FuG14jAywfp9MyF4nXv J+QsfB7qm9aCnGg7ATVavzscL7SGnFzjbxHmKX3JRfrFs2MXgiSpkb+smtQrzTSZBLMf smJv6KyUj3S67DWZZNg/EpjybpCwjMOdJ/7wX4uIxiyA5fdwngRWSZKEosXpOvyI+dqn qjKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=SrPoM1bL; dkim=pass header.i=@codeaurora.org header.s=default header.b=FI4UjuEt; 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 g33-v6si2068814plb.297.2018.04.27.14.57.33; Fri, 27 Apr 2018 14:57:46 -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=@codeaurora.org header.s=default header.b=SrPoM1bL; dkim=pass header.i=@codeaurora.org header.s=default header.b=FI4UjuEt; 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 S1759415AbeD0V4G (ORCPT + 99 others); Fri, 27 Apr 2018 17:56:06 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:32892 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759307AbeD0V4E (ORCPT ); Fri, 27 Apr 2018 17:56:04 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 570A460C66; 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= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 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 Cc: Mark Rutland , Jan Glauber , Kees Cook , Ard Biesheuvel , Catalin Marinas , Will Deacon , Laura Abbott , Timur Tabi , Stephen Smalley , Andrew Morton , Ingo Molnar , Thomas Gleixner , Peter Zijlstra , Jeffrey Hugo 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 -- Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.