From patchwork Tue Apr 25 22:56:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9700043 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 D9BD560224 for ; Tue, 25 Apr 2017 22:57:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4EF5283FE for ; Tue, 25 Apr 2017 22:57:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8E51284EE; Tue, 25 Apr 2017 22:57:01 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 88AF1283FE for ; Tue, 25 Apr 2017 22:56:58 +0000 (UTC) Received: (qmail 9678 invoked by uid 550); 25 Apr 2017 22:56:55 -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 9656 invoked from network); 25 Apr 2017 22:56:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ql/5XkDNPwIhTxtQErexdK5RA15BuSqZBzY2hMN7Wcs=; b=JJBlDNneioIeIv1nyCUIV2Wgs0yyas5KctIe6lVfjaQSteYg+oFhxXzEqatgChkt6Z BmKo9w+KG8yW8D3I1lLJFwC2OtYrBlMfUKYaU2iRMPUbBNnyefkMP0jQLuSI0xzEssI7 viaQ+Pa5ni2h4UjjcQDJxqzpfNiXTe/FFsIi4= 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; bh=Ql/5XkDNPwIhTxtQErexdK5RA15BuSqZBzY2hMN7Wcs=; b=KBnptsYSFA/04IC88Q4mn7axkoINDULZkUFM3+9SKmHMfNfGOyxaqGWQX8lbpGg+9i 3FLvgzGGZ6paum9WW6ZtSzZI7w/loSxM1xQexiU70EnUES9GCyM8i5KUQfpQ8LKLie6R ZzUzuS6v30+yXA/9M2V3ZN3mKKEIm5Sn7YH8Ar1iGJZ4d4xEkoOdIBmdO+f+CnfPRjfB iE/qaPlwuQgr2gRUS2PY/KzFA7K/blqqW9ryAaqxpqd1H4GUNsQde9p92/Aow3026QrL 0c24njdLbPiPQcOd8Cd9WFyjTznasr9b0Q0LgssHzTvUcX4MxLtV9LffY6ai7PJitq6F yaJA== X-Gm-Message-State: AN3rC/7xmhEByJStNIJ3HqX3JJ2714JZN90a6+GtUlCZcATFeWdwrsMi zfzEsCTw/ADsVYy5 X-Received: by 10.36.185.5 with SMTP id w5mr7838941ite.1.1493161003338; Tue, 25 Apr 2017 15:56:43 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Peter Zijlstra , PaX Team , Jann Horn , Eric Biggers , Christoph Hellwig , "axboe@kernel.dk" , James Bottomley , Elena Reshetova , Hans Liljestrand , David Windsor , "x86@kernel.org" , Ingo Molnar , Arnd Bergmann , Greg Kroah-Hartman , "David S. Miller" , Rik van Riel , linux-arch , "kernel-hardening@lists.openwall.com" Date: Tue, 25 Apr 2017 15:56:36 -0700 Message-Id: <1493160997-126108-2-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493160997-126108-1-git-send-email-keescook@chromium.org> References: <1493160997-126108-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH v2 1/2] x86, asm: Add suffix macro for GEN_*_RMWcc() X-Virus-Scanned: ClamAV using ClamSMTP The coming x86 refcount protection needs to be able to add trailing instructions to the GEN_*_RMWcc() operations. This extracts the difference between the goto/non-goto cases so the helper macros can be defined outside the #ifdef cases. Additionally adds argument naming to the resulting asm for referencing from suffixed instructions. Signed-off-by: Kees Cook --- arch/x86/include/asm/rmwcc.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h index 661dd305694a..3e96f9a56b6d 100644 --- a/arch/x86/include/asm/rmwcc.h +++ b/arch/x86/include/asm/rmwcc.h @@ -8,18 +8,15 @@ #define __GEN_RMWcc(fullop, var, cc, ...) \ do { \ asm_volatile_goto (fullop "; j" #cc " %l[cc_label]" \ - : : "m" (var), ## __VA_ARGS__ \ + : : [counter] "m" (var), ## __VA_ARGS__ \ : "memory" : cc_label); \ return 0; \ cc_label: \ return 1; \ } while (0) -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \ - __GEN_RMWcc(op " " arg0, var, cc) +#define __BINARY_RMWcc_ARG " %1, " -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \ - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val)) #else /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */ @@ -29,17 +26,26 @@ cc_label: \ do { \ bool c; \ asm volatile (fullop ";" CC_SET(cc) \ - : "+m" (var), CC_OUT(cc) (c) \ + : [counter] "+m" (var), CC_OUT(cc) (c) \ : __VA_ARGS__ : "memory"); \ return c; \ } while (0) +#define __BINARY_RMWcc_ARG " %2, " + +#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */ + #define GEN_UNARY_RMWcc(op, var, arg0, cc) \ __GEN_RMWcc(op " " arg0, var, cc) +#define GEN_UNARY_SUFFIXED_RMWcc(op, suffix, var, arg0, cc) \ + __GEN_RMWcc(op " " arg0 "\n\t" suffix, var, cc) + #define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \ - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val)) + __GEN_RMWcc(op __BINARY_RMWcc_ARG arg0, var, cc, vcon (val)) -#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */ +#define GEN_BINARY_SUFFIXED_RMWcc(op, suffix, var, vcon, val, arg0, cc) \ + __GEN_RMWcc(op __BINARY_RMWcc_ARG arg0 "\n\t" suffix, var, cc, \ + vcon (val)) #endif /* _ASM_X86_RMWcc */