From patchwork Fri Feb 17 16:51:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 9580403 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 CA145600F6 for ; Fri, 17 Feb 2017 16:51:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B86AB28731 for ; Fri, 17 Feb 2017 16:51:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD42428748; Fri, 17 Feb 2017 16:51:52 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4299628731 for ; Fri, 17 Feb 2017 16:51:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From: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=0J5qSuEXyqu+BgmpWr8YOgaJ1JgyhbSvoAvWghNKgE4=; b=OQw BELDxxGcfG2qGvLKhoIuATP8aaOy1EhYd5z4iF6iI4WLN1HqcSvhdAkr1EwJ4cgxs/u7ydBrqxiz7 LYI1zVEW4asp8L6VJlHMqUD4/B3fCXOuq0w16DizjXbW+zPcUFz4BlWin2zaxREwG02AyQ5LH+H6Y dxzXvtv1+wjU8EtGehVTE9JPZqj3rWW7riBnLR7lRX5ZgjBdP8X6rkiIaAgKICDU3oMrKAzn9SL4w r0KH8xXxEsgAK06D9DoN8MECyR5WhPrP2iVsiM/YGU+I8byAojUgEek2arMeWWW5ufgcz2T7fXzyC 9zW8DGfujzvrqUzuS7pPuJl5BkHaoLQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1celkx-0000lx-1R; Fri, 17 Feb 2017 16:51:39 +0000 Received: from mail-pg0-x232.google.com ([2607:f8b0:400e:c05::232]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1celkt-0000k8-G3 for linux-arm-kernel@lists.infradead.org; Fri, 17 Feb 2017 16:51:37 +0000 Received: by mail-pg0-x232.google.com with SMTP id z67so16916388pgb.1 for ; Fri, 17 Feb 2017 08:51:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=r5nJ4ZJa6rn4uFiIMdUyJ3aeItd91Sox7htZlLJBeas=; b=gdYa56SAU1Wf3Xuk+tBLJf4Au4cLgq4stFYxceuWKY9/S75KUkWyTk/Pl9fRB7E2ry 8sA5azwC6hgd9Jx8Y6ap/QQCTLwQWVeXyyRBGtYzbxy3MO9TnPuAago8TCXI8rs/+bsn tXogp6BsjvYBbeHV2cghOKr6xBjji8Z5fN7lk= 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; bh=r5nJ4ZJa6rn4uFiIMdUyJ3aeItd91Sox7htZlLJBeas=; b=EPs1n6I4b++Y1Wu1VuoX78oPgdAhZLRd6f0QSpQmU29J/dt/ZQ8C8JtxVyCrQDu6rD H7s0GuiiZ0yfyP7nZiRWPNQ3LY9Z1ZRfxucuvblWFL2A6w2bdEwSKQV7s1cLdxgZCU+5 FmDjwe/r5dWqnv2YqKtOvt6ZntY6L86H/AUCkBRbWUg8892fNVRjUkGDItoyw4iNOx8G Au0YLi4/xhCe4bRM0iYDtHN43zOV4zlKnF2OJHqWljJ2u5NLDnkSeGnuU6QxlwgyPKjm rwMVxPztLkRmLY+MUa7O2hNVH7ANGf1J18mXtii37putG8tGo4/3s0HES1pQ3mX8iBrv NHxQ== X-Gm-Message-State: AMke39kDHHpJ7edr6iR3k3uOY/Um3eai/yX/W2fIaQCsWJ+Mq+4hsQ8Q2CGfEtTCQ3xfh21Z X-Received: by 10.98.9.206 with SMTP id 75mr10556527pfj.159.1487350274395; Fri, 17 Feb 2017 08:51:14 -0800 (PST) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id l71sm20822933pga.13.2017.02.17.08.51.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Feb 2017 08:51:13 -0800 (PST) From: Stephen Boyd To: Catalin Marinas , Will Deacon Subject: [PATCH] arm64: traps: Mark __le16, __le32, __user variables properly Date: Fri, 17 Feb 2017 08:51:12 -0800 Message-Id: <20170217165112.17512-1-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170217_085135_575564_B7E1AF17 X-CRM114-Status: GOOD ( 14.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Punit Agrawal , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Sparse complains a bit on this file about endian issues and __user casting: arch/arm64/kernel/traps.c:87:37: warning: incorrect type in argument 1 (different address spaces) arch/arm64/kernel/traps.c:87:37: expected void const volatile [noderef] * arch/arm64/kernel/traps.c:87:37: got unsigned long * arch/arm64/kernel/traps.c:116:23: warning: incorrect type in argument 1 (different address spaces) arch/arm64/kernel/traps.c:116:23: expected void const volatile [noderef] * arch/arm64/kernel/traps.c:116:23: got unsigned int [usertype] * arch/arm64/kernel/traps.c:346:25: warning: cast to restricted __le16 arch/arm64/kernel/traps.c:352:34: warning: cast to restricted __le16 arch/arm64/kernel/traps.c:359:25: warning: cast to restricted __le32 Mark the types appropriately, and force the cast in get_user() when assigning to 0 so sparse doesn't complain. The resulting object code is the same before and after this commit. Cc: Punit Agrawal Cc: Mark Rutland Signed-off-by: Stephen Boyd --- Noticed while making other changes to this file. There are other issues still about marking symbols static, but I'm not sure we want to introduce another header file for the asmlinkage functions? arch/arm64/kernel/traps.c:429:29: warning: symbol 'do_undefinstr' was not declared. Should it be static? arch/arm64/kernel/traps.c:529:29: warning: symbol 'do_sysinstr' was not declared. Should it be static? arch/arm64/kernel/traps.c:544:17: warning: symbol 'do_ni_syscall' was not declared. Should it be static? arch/arm64/kernel/traps.c:615:17: warning: symbol 'bad_mode' was not declared. Should it be static? arch/arm64/kernel/traps.c:632:17: warning: symbol 'bad_el0_sync' was not declared. Should it be static? arch/arm64/kernel/traps.c:722:12: warning: symbol 'early_brk64' was not declared. Should it be static? arch/arm64/kernel/traps.c:567:10: warning: Initializer entry defined twice arch/arm64/kernel/traps.c:568:10: also defined here arch/arm64/include/asm/uaccess.h | 2 +- arch/arm64/kernel/traps.c | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 46da3ea638bb..2f5b4ae98ee0 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -287,7 +287,7 @@ do { \ might_fault(); \ access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \ __get_user((x), __p) : \ - ((x) = 0, -EFAULT); \ + ((x) = (__force __typeof__(*(ptr)))0, -EFAULT); \ }) #define __put_user_asm(instr, alt_instr, reg, x, addr, err, feature) \ diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 659b2e6b6cf7..23959cb70ded 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -84,7 +84,7 @@ static void dump_mem(const char *lvl, const char *str, unsigned long bottom, if (p >= bottom && p < top) { unsigned long val; - if (__get_user(val, (unsigned long *)p) == 0) + if (__get_user(val, (unsigned long __user *)p) == 0) sprintf(str + i * 17, " %016lx", val); else sprintf(str + i * 17, " ????????????????"); @@ -113,7 +113,7 @@ static void __dump_instr(const char *lvl, struct pt_regs *regs) for (i = -4; i < 1; i++) { unsigned int val, bad; - bad = __get_user(val, &((u32 *)addr)[i]); + bad = __get_user(val, &((u32 __user *)addr)[i]); if (!bad) p += sprintf(p, i == 0 ? "(%08x) " : "%08x ", val); @@ -340,23 +340,28 @@ static int call_undef_hook(struct pt_regs *regs) return 1; if (compat_thumb_mode(regs)) { + __le16 tinst; + /* 16-bit Thumb instruction */ - if (get_user(instr, (u16 __user *)pc)) + if (get_user(tinst, (__le16 __user *)pc)) goto exit; - instr = le16_to_cpu(instr); + instr = le16_to_cpu(tinst); if (aarch32_insn_is_wide(instr)) { - u32 instr2; + __le16 tinstr2; + u16 instr2; - if (get_user(instr2, (u16 __user *)(pc + 2))) + if (get_user(tinstr2, (__le16 __user *)(pc + 2))) goto exit; - instr2 = le16_to_cpu(instr2); + instr2 = le16_to_cpu(tinstr2); instr = (instr << 16) | instr2; } } else { + __le32 ainst; + /* 32-bit ARM instruction */ - if (get_user(instr, (u32 __user *)pc)) + if (get_user(ainst, (__le32 __user *)pc)) goto exit; - instr = le32_to_cpu(instr); + instr = le32_to_cpu(ainst); } raw_spin_lock_irqsave(&undef_lock, flags);