Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B062C433E2 for ; Tue, 15 Sep 2020 20:32:43 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 38837207DE for ; Tue, 15 Sep 2020 20:32:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jafs4BRN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 38837207DE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=tinet.cat Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From:Date: 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=/LNHvbYr1WEMYgQfs7MdYtwPLUYLX5uA0Lgsyr21J+E=; b=jafs4BRNG2Cr8bjyNM2zFQyVGm X3OKg0r+5s1/9guheHn5c8d3+6dGalzJQabohdnIuVAysaeZReMkZbnIR/0XIJqfnWDe34qaoWLw3 YruyKCSKurKbG/DHhw0KUF8HzKQfzYEuJKcF1ghm2h/hWxXo4RCM1s5yruDV6ImfKmL0uTMFOgbwm 6VMBI2ttst/gdtERu0X8jhoL/iSNhPsWgdrcU0dp6kj9X9p3ns8pPO2w/l10D/YDNDR/iCwUXCfWd vQSwPcI/vHstL6/LrEZOyNjqXnKUlMQyc/4DEGapEj3P4muq9J0LUVpLqq9J3FDDZjSQvukqsmES7 CpqAi3Sg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIHbY-0002Ng-Bz; Tue, 15 Sep 2020 20:31:08 +0000 Received: from mx1.dipta.cat ([195.76.233.59] helo=mx1.tinet.cat) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIHbV-0002M9-VM for linux-arm-kernel@lists.infradead.org; Tue, 15 Sep 2020 20:31:07 +0000 X-ASG-Debug-ID: 1600201837-12aaf22b233acdb80001-tbGyMd Received: from smtp01.tinet.cat (smtp.tinet.cat [195.77.216.131]) by mx1.tinet.cat with ESMTP id p3GVHItU8Nj2Vu9A; Tue, 15 Sep 2020 22:30:37 +0200 (CEST) X-Barracuda-Envelope-From: xdrudis@tinet.cat X-Barracuda-Effective-Source-IP: smtp.tinet.cat[195.77.216.131] X-Barracuda-Apparent-Source-IP: 195.77.216.131 Received: from martinet.casa.ct (155.red-83-36-226.dynamicip.rima-tde.net [83.36.226.155]) by smtp01.tinet.cat (Postfix) with ESMTPSA id A71C6603D1C0; Tue, 15 Sep 2020 22:30:37 +0200 (CEST) Received: from xdrudis by martinet.casa.ct with local (Exim 4.92) (envelope-from ) id 1kIHb3-0004Yz-J5; Tue, 15 Sep 2020 22:30:37 +0200 Date: Tue, 15 Sep 2020 22:30:37 +0200 From: Xavi Drudis Ferran To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] ARM: imx: W+X ocram page in imx6q. Might someone with working imx6 suspend please test ? Message-ID: <20200915203037.GA13650@martinet.casa.ct> X-ASG-Orig-Subj: [PATCH] ARM: imx: W+X ocram page in imx6q. Might someone with working imx6 suspend please test ? MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Barracuda-Connect: smtp.tinet.cat[195.77.216.131] X-Barracuda-Start-Time: 1600201837 X-Barracuda-URL: https://195.76.233.59:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at tinet.cat X-Barracuda-Scan-Msg-Size: 3230 X-Barracuda-Bayes: SPAM GLOBAL 1.0000 1.0000 4.3430 X-Barracuda-Spam-Score: 4.34 X-Barracuda-Spam-Status: No, SCORE=4.34 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=6.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.84650 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200915_163106_132059_AF64C989 X-CRM114-Status: GOOD ( 20.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sascha Hauer , Shawn Guo , NXP Linux Team Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hello and thanks for your work. A custom .config of linux-libre-5.8, linux-libre-5.8.3, linux-libre-5.8.8 and linux-libre-5.8.9 with CONFIG_DEBUG_WX on gave me a W+X memory protection warning for the page mapping the On-Chip RAM used to hold the resume assembler code. Or at least the warning goes away with a patch that marks the page read-only once the code has been copied there. I've only tested this patch on linux-libre-5.8.9, the other versions were tested with a worse patch that at least seemed to confirm the ocram suspend page had the W+X. Thanks to Laura Abbott for pointing me to set_memory_ro. I don't have any exploit, not sure how possible/difficult it would be, and I'm not sure what impact this could have. I haven't looked at what would be the first version affected (since suspend for imx6 maybe?). I'm not sure whether the patch breaks anything. In my tests I have the same problems with suspend to ram and hibernation on a Wandboard Quad SBC, both with or without my patch. So maybe I should wait until I have working suspend and hibernation or maybe someone with a working suspend on imx6q could test it ? It did not seem to me, reading the assembler in that page (arch/arm/mach-imx/suspend-imx6.S), that it could need write access to its page (only for loading the code there), but my assembler skill is not very good. Completely new here, so thanks for any tips. Do you need more info, logs, etc.? Also, with this patch if all went well but the page could not be made readonly imx6q_suspend_init will return error (because of a potential vulnerability that shouldn't be there). But it could also be argued that since suspend should work just fine with W+X it should only print the warning and return 0? Thank you very much. The patch would be: imx6q: Mark the SRAM page for resume code read-only,executable (once written) The code used for resume after suspend in imx6 is copied to a SRAM on chip, so that it stays in the CPU chip while the system is partially powered down. The page mapping that SRAM was marked as RW+X, which gave a warning when CONFIG_DEBUG_WX=y. Mark it read-only and executable once the writting from kernel text is done to get rid of the warning and prevent possible exploitation. Signed-off-by: Xavier Drudis Ferran diff --git a/arch/arm/mach-imx/pm-imx6.c b/arch/arm/mach-imx/pm-imx6.c index 40c74b4c4..61f296599 100644 --- a/arch/arm/mach-imx/pm-imx6.c +++ b/arch/arm/mach-imx/pm-imx6.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -570,6 +571,13 @@ static int __init imx6q_suspend_init(const struct imx6_pm_socdata *socdata) &imx6_suspend, MX6Q_SUSPEND_OCRAM_SIZE - sizeof(*pm_info)); + ret = set_memory_ro(suspend_ocram_base, + __KERNEL_DIV_ROUND_UP(MX6Q_SUSPEND_OCRAM_SIZE, PAGE_SIZE)); + if (ret) { + pr_warn("%s: failed to mark executable on chip SRAM as read only after writing to it: %d!\n", + __func__, ret); + } + goto put_device; pl310_cache_map_failed: _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel