From patchwork Thu Feb 21 09:36:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 10823385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D93A51390 for ; Thu, 21 Feb 2019 09:37:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C923D3025A for ; Thu, 21 Feb 2019 09:37:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA92D30277; Thu, 21 Feb 2019 09:37:31 +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=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id EF8413025A for ; Thu, 21 Feb 2019 09:37:30 +0000 (UTC) Received: (qmail 27688 invoked by uid 550); 21 Feb 2019 09:36:54 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 26561 invoked from network); 21 Feb 2019 09:36:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=russell.cc; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=tq/uYvjK6K2rr yCtaH/i03liKnHzLrIx4TwZPHaWGUs=; b=l4+7LG6A7b/xOrClgpInPzAo04W37 iiKSzeTPKTrMJyuabl1ccqVIQ8nP6z8SZzHDsbSDMyePdy4dCnbKnJaaFCThe4C4 w72O5L9n8daDxGAIUT/sREHMtq7r/saiyeOhbn9FZnWi9q9VFIMFoKRc1ALMeT2Y 32TA+nzeaZaHEtQ6HVsT5UlKSAeK7uZACzjURDWt+GGJer9Cqa1VCYgK6qCdf7hk fKKyf/sK+lqsYaF1hgzWYo3osqelVIjl+xsP7dgoQuZssd6gSrzslSf6RJ5INLpk viA3dAdOxJcMJC1/3DWdzGBCDtZLHcH5+WLus4oFEH+eFk6brr5e+o/GQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=tq/uYvjK6K2rryCtaH/i03liKnHzLrIx4TwZPHaWGUs=; b=r8xtgTxB 9xF18QG8OKTHiuo6bSYRt6rUPdxD7mkbpIcpJ/PJQeaShpbjGwyeOQvfGOOMTaio 0v3Y8lSAUPUtUJucBtss7RO7SgcFGWZ9ZEapVbNsX8UjNkYtP2o2dNpbBSzEuiDt BosZG0xIbXoXQ+KFsoORyJkdqozKHiEe7IUdQm26494AwgL0+1Pq/ZO44+vGd2/Q 24Kmn8Mjis/9dT5xYh8W7o/cbzLrdm9+GcDPiaba4JIQmSmSV6cICcNd5XN+5QCK wlAUgCuZ+xuMYgGGmPFCibBNFz5IRirfUmjQ5SZ8IBtxpItM5TJ+ge2J0YUUqZdB Z/QhqSQg6mZQlw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrtdekgddtjeculddtuddrgedtledrtddtmd cutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfedtmdenucfjughrpefhvf fufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfhushhsvghllhcuvehurhhr vgihuceorhhushgtuhhrsehruhhsshgvlhhlrdgttgeqnecukfhppeduvddvrdelledrke dvrddutdenucfrrghrrghmpehmrghilhhfrhhomheprhhushgtuhhrsehruhhsshgvlhhl rdgttgenucevlhhushhtvghrufhiiigvpeef X-ME-Proxy: From: Russell Currey To: linuxppc-dev@lists.ozlabs.org Cc: mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@c-s.fr, kernel-hardening@lists.openwall.com, Russell Currey Subject: [PATCH 6/7] powerpc/lib: Refactor __patch_instruction() to use __put_user_asm() Date: Thu, 21 Feb 2019 20:36:00 +1100 Message-Id: <20190221093601.27920-7-ruscur@russell.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221093601.27920-1-ruscur@russell.cc> References: <20190221093601.27920-1-ruscur@russell.cc> MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP __patch_instruction() is called in early boot, and uses __put_user_size(), which includes the locks and unlocks for KUAP, which could either be called too early, or in the Radix case, forced to use "early_" versions of functions just to safely handle this one case. __put_user_asm() does not do this, and thus is safe to use both in early boot, and later on since in this case it should only ever be touching kernel memory. __patch_instruction() was previously refactored to use __put_user_size() in order to be able to return -EFAULT, which would allow the kernel to patch instructions in userspace, which should never happen. This has the functional change of causing faults on userspace addresses if KUAP is turned on, which should never happen in practice. A future enhancement could be to double check the patch address is definitely allowed to be tampered with by the kernel. Signed-off-by: Russell Currey --- arch/powerpc/lib/code-patching.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index 506413a2c25e..42fdadac6587 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -26,9 +26,9 @@ static int __patch_instruction(unsigned int *exec_addr, unsigned int instr, unsigned int *patch_addr) { - int err; + int err = 0; - __put_user_size(instr, patch_addr, 4, err); + __put_user_asm(instr, patch_addr, err, "stw"); if (err) return err;