From patchwork Fri Dec 21 18:14:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10740869 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 29A46924 for ; Fri, 21 Dec 2018 18:17:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D004284AA for ; Fri, 21 Dec 2018 18:17:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 104AF28622; Fri, 21 Dec 2018 18:17:07 +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.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,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 2993A284AA for ; Fri, 21 Dec 2018 18:17:05 +0000 (UTC) Received: (qmail 3352 invoked by uid 550); 21 Dec 2018 18:15:21 -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 3271 invoked from network); 21 Dec 2018 18:15:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=SF4qk+bTzK3es4UM9b0qE6afh8/8sQWLd3sxWcWkQd8=; b=Ii7ELF8/5y1rVaPhHiLhgDtq4P7/rfzqXnM3EeCH5GRSr2Kq2zzNF5t8kZw3ND0+a6 10vlyhvH2ZArYPGzD8PwHtf9EFg96E8dJK8mNhL944qEkX0oPwo3++zWdGQklQ9CWU8B ETzu3Boaxa10N5Nt8r1xtE9gTtRaR9kkLpPgE8BLmp1z/ycZC0NNjjNhkSeV27VB58Vh cylWppIJrf8u0uC15//e4cctuMhk9qlnQyspjtHkl2k33XBKfEPLw9N9gKQ8QuMGKnxR 26HLuc8Ps/OA9fdgIFgv2Zi8d3KV46SAyUsiabS45ayIX64sTa1CQlIsMkc80vD0t48o vIng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=SF4qk+bTzK3es4UM9b0qE6afh8/8sQWLd3sxWcWkQd8=; b=qrjuQOoY+4/ApyW9ewla/Zq/k6Jhf2RnDsYDOMSSphilINTCJ0aC67m+MC1zbd4oPP cF7dF6LgulcTFRlxQe6ruZ3rz9QTuYz0EiaAhFwbdo9koUlN55Js4fwhmrCMeE7/AfaT sYgfWu2cRdfN1xOhx3mI9SykbxIluJPEqO+8kMptKfgG9csJzyN+MqVeOIStwBH9LVma kpWyDTJ3VX49uQkJMdHFmv/g62KrLeGbINVRCSUhObzh46p835Y33J1IOEcsZX+nArW5 vR2ZTK4mjFX3S5Ux1vug9IsihKIoFZd7quB1oe7MkNYrMaDyJN0v3/8QRU/pEaKxCP2y G+Yw== X-Gm-Message-State: AA+aEWaLRx3e4dZT0ZovLX5fxdGKS79UQQRB0wBx5IJDI6g7pIGTfDAl /EFAQ7w6kFwRQ7UX0Q3vP+4= X-Google-Smtp-Source: AFSGD/U5nUYrabzF4bcWijW9jX9KfZDA5WG1g0TgA4b42uvAMM3t6RmJ/Cf3Ft6Rt3AgJtUscpiQGw== X-Received: by 2002:a2e:9cd2:: with SMTP id g18-v6mr2461814ljj.161.1545416109279; Fri, 21 Dec 2018 10:15:09 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar , Thiago Jung Bauermann Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , Ahmed Soliman , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/12] x86_64: __clear_user as case of __memset_user Date: Fri, 21 Dec 2018 20:14:23 +0200 Message-Id: <20181221181423.20455-13-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181221181423.20455-1-igor.stoppa@huawei.com> References: <20181221181423.20455-1-igor.stoppa@huawei.com> MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP To avoid code duplication, re-use __memset_user(), when clearing user-space memory. The overhead should be minimal (2 extra register assignments) and outside of the writing loop. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- arch/x86/lib/usercopy_64.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c index 84f8f8a20b30..ab6aabb62055 100644 --- a/arch/x86/lib/usercopy_64.c +++ b/arch/x86/lib/usercopy_64.c @@ -69,34 +69,7 @@ EXPORT_SYMBOL(memset_user); unsigned long __clear_user(void __user *addr, unsigned long size) { - long __d0; - might_fault(); - /* no memory constraint because it doesn't change any memory gcc knows - about */ - stac(); - asm volatile( - " testq %[size8],%[size8]\n" - " jz 4f\n" - "0: movq $0,(%[dst])\n" - " addq $8,%[dst]\n" - " decl %%ecx ; jnz 0b\n" - "4: movq %[size1],%%rcx\n" - " testl %%ecx,%%ecx\n" - " jz 2f\n" - "1: movb $0,(%[dst])\n" - " incq %[dst]\n" - " decl %%ecx ; jnz 1b\n" - "2:\n" - ".section .fixup,\"ax\"\n" - "3: lea 0(%[size1],%[size8],8),%[size8]\n" - " jmp 2b\n" - ".previous\n" - _ASM_EXTABLE_UA(0b, 3b) - _ASM_EXTABLE_UA(1b, 2b) - : [size8] "=&c"(size), [dst] "=&D" (__d0) - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr)); - clac(); - return size; + return __memset_user(addr, 0, size); } EXPORT_SYMBOL(__clear_user);