Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4DD2C6FD1D for ; Tue, 4 Apr 2023 10:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :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=VruUNvdwn0+SqT3h712Q/q5vGyYhQ3sCBus0wZVEBpo=; b=cv0hj91A01/XJb ggmtVC+lKLJV9hmzTz9HPwIRBn02HXNKcA2XRvc1NZmyqck/XHXPMP/cwSM0904vvuSE/6goUsBsC PvQH38hxkL1Vw6UegsicqpL3PY0P5+GhLL3sO8LsJYClrIk+8F5BWIECM7fCYNoz+sYaICxxaajD3 9kpNPT6aTiK4cMoTPyIG7A0FgdQPnBrCqS1xsSSFHEP2+XJzzG24C1ZRwILKl+Ubxp01DFv0eQzM9 w35VD3ytJzhEhfw4QAn9eUn4c32hwCON98fUxB90O6uJKq41Z27Lt11JJePwkEJ7TpxyYXi/yKw3X OYxgOZmvPlGMx/kvWUiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pje1w-000uGc-0G; Tue, 04 Apr 2023 10:36:48 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pje1t-000uFk-0Q for linux-arm-kernel@lists.infradead.org; Tue, 04 Apr 2023 10:36:46 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0287E60FB2; Tue, 4 Apr 2023 10:36:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 174C1C433EF; Tue, 4 Apr 2023 10:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680604602; bh=bveOdNC19YEEDToUJ+a25pnA62Ma4x8mNJEB65NNolE=; h=From:To:Cc:Subject:Date:From; b=dNuWJLQ9B8NlmnJxvfQqEJkxLwSziwXUqPLuwl4BxrMH311OXuk0w1YmtCBdh1bKy 9MlyL80Lac7YOIuTVLn8/Aq+2QUE/zxyb9zQfkHYb4msXjp68C11ZWK6xDn1HE94Y5 1UY1PwRUUZJc++PxSjR1MoL2q81x6JKyeox2kVv/LP0pLqZexrO3iTj80WMEgmQXse ta3+aJuIz4U3gqTueap0KlpTsi4gOaAAa3Obnl9o7eg3CgqmJ0hIosUgoQ+UnCt4mP qzXlwdbQD2aqTqSVJN8vH23M0xF8oatKgNx1t6NPV/NrcSeioP2r+2/JRCxPgj5sHe QkKaVi8Kqaskg== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: will@kernel.org, catalin.marinas@arm.com, Ard Biesheuvel , kernel test robot , Dan Carpenter Subject: [PATCH] arm64: compat: Work around uninitialized variable warning Date: Tue, 4 Apr 2023 12:36:25 +0200 Message-Id: <20230404103625.2386382-1-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2797; i=ardb@kernel.org; h=from:subject; bh=bveOdNC19YEEDToUJ+a25pnA62Ma4x8mNJEB65NNolE=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIUX770rJtdrG8/R4Tt994+ITIf2g+MMN5j2VHKuzYz5fF +2cKJzfUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACby6jQjw8Ub2+PEPycdkD/J mS8iYM2qxdfu+OJ5fNWM6sJtat3XexgZ1u1+ODF1193IcL2kRYWSokcad7ktCV1yMyO7aN61hZN y2QE= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230404_033645_266799_ED34E772 X-CRM114-Status: GOOD ( 17.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Dan reports that smatch complains about a potential uninitialized variable being used in the compat alignment fixup code. The logic is not wrong per se, but we do end up using an uninitialized variable if reading the instruction that triggered the alignment fault from user space faults, even if the fault ensures that the uninitialized value doesn't propagate any further. Given that we just give up and return 1 if any fault occurs when reading the instruction, let's get rid of the 'success handling' pattern that captures the fault in a variable and aborts later, and instead, just return 1 immediately if any of the get_user() calls result in an exception. Fixes: 3fc24ef32d3b9368 ("arm64: compat: Implement misalignment fixups for multiword loads") Reported-by: kernel test robot Reported-by: Dan Carpenter Link: https://lore.kernel.org/r/202304021214.gekJ8yRc-lkp@intel.com/ Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/compat_alignment.c | 32 ++++++++++++---------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/arch/arm64/kernel/compat_alignment.c b/arch/arm64/kernel/compat_alignment.c index 5edec2f49ec98c9b..deff21bfa6800cfc 100644 --- a/arch/arm64/kernel/compat_alignment.c +++ b/arch/arm64/kernel/compat_alignment.c @@ -314,36 +314,32 @@ int do_compat_alignment_fixup(unsigned long addr, struct pt_regs *regs) int (*handler)(unsigned long addr, u32 instr, struct pt_regs *regs); unsigned int type; u32 instr = 0; - u16 tinstr = 0; int isize = 4; int thumb2_32b = 0; - int fault; instrptr = instruction_pointer(regs); if (compat_thumb_mode(regs)) { __le16 __user *ptr = (__le16 __user *)(instrptr & ~1); + u16 tinstr, tinst2; - fault = alignment_get_thumb(regs, ptr, &tinstr); - if (!fault) { - if (IS_T32(tinstr)) { - /* Thumb-2 32-bit */ - u16 tinst2; - fault = alignment_get_thumb(regs, ptr + 1, &tinst2); - instr = ((u32)tinstr << 16) | tinst2; - thumb2_32b = 1; - } else { - isize = 2; - instr = thumb2arm(tinstr); - } + if (alignment_get_thumb(regs, ptr, &tinstr)) + return 1; + + if (IS_T32(tinstr)) { /* Thumb-2 32-bit */ + if (alignment_get_thumb(regs, ptr + 1, &tinst2)) + return 1; + instr = ((u32)tinstr << 16) | tinst2; + thumb2_32b = 1; + } else { + isize = 2; + instr = thumb2arm(tinstr); } } else { - fault = alignment_get_arm(regs, (__le32 __user *)instrptr, &instr); + if (alignment_get_arm(regs, (__le32 __user *)instrptr, &instr)) + return 1; } - if (fault) - return 1; - switch (CODING_BITS(instr)) { case 0x00000000: /* 3.13.4 load/store instruction extensions */ if (LDSTHD_I_BIT(instr)) -- 2.39.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel