From patchwork Fri Jan 7 23:27:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12707128 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 11FC6C433F5 for ; Fri, 7 Jan 2022 23:29:07 +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=q0xT5NG9F+7Z5SQBW91WMdN+7TeMGr+/gfmLf2lem+w=; b=YKYv9Q5YmS0AqH xO+Eg14Hz2icApPP+MACqG4FqQoSR0wtoQzN8SljaKTvqaDwC/DpWKZ1gNtqsXTt2OVdBVkeGqvkx fZWWW7glhGLVcXbR6Ejb/EkAHbiNfJUiZp/7V51PB8TTvPXIagoPHAyJ3CBaHZ4vNCzmoLk0ifXu1 J3daaL3in1T06y2YvZMYucgkGvKDdomkMQ6n873EiULI55UXlc9ariZIOsrMg/eo4DMQyF2KKLs54 FIcaeWqQlI1Igt58wJxxDnwxtxl7cQSq1HaajNUUQFO35NBhMQ67CKf3vY5N0QT+tRoil3AFZ0nI3 eVd5Z/edcKbRrMu3DvAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5yeI-005V7b-Ad; Fri, 07 Jan 2022 23:27:54 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5yeE-005V6u-In for linux-arm-kernel@lists.infradead.org; Fri, 07 Jan 2022 23:27:52 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 200so6963200pgg.3 for ; Fri, 07 Jan 2022 15:27:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6Gm2/5HnEXFIxSdkPzjXZQKOU+LWmT6qpXAHCEvGO7U=; b=bYLC3+tD1xZ8RuuhpF8gh7ly6f8+HHlRPcRcwotINN7eSLgj+T+hk7koQtcheiDVZe ENtIZEZ7FmtoC2rkmYPOUJM086bRcykmjhqPCKpM0fV2FrHtTr9PFhtej3PrLM4beYdQ llM/shaf8FknoJfeSOrUrv7+VM7iLQOc7pVVY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6Gm2/5HnEXFIxSdkPzjXZQKOU+LWmT6qpXAHCEvGO7U=; b=1JYv6WDO4BNH3HVBhusNw3oew5/qXZPTUVqqUlNXQDhLMc94Ne5qmpk9m8uTOOITGk FAZqG+qM9zE9P87VuKXkivx1V45dz4JcOdXqM63Qh0rZFhcK/udI/Vj9ommn8fHxR2ct iRolmtZOsoLvmg5IJyg1nULmtt+l+40BbKITpyMaFyeKTIfUfmPScxZ8Mkp0YZ2bzMRl MLB61R8hlGYPbNKc3HY6lkcxcOv4iKpjPIlx9UkQr3N4lJByFKkAM7XRAHXBYP/IPFYq VCYSJRckDwQhNyVmaYKD6LVk/heAn8o03dgQMWQX2lu1v3QOr7Fcb/OE8K7GVAUYvfaJ tUXw== X-Gm-Message-State: AOAM533auBPm83xKPh4cj7Fz4HBX9qWIEvTsTaqa1lGw+3EpeG3aZPHp mSKpA8d7zCJ8sKVuoSQA7NpEPA== X-Google-Smtp-Source: ABdhPJxkDgZCqGiDKCf+UvMXdHbCz0HH/CZI6YKoT+aZI04YLxIT48GaCscg6c62MbkVCjQEd4hQWA== X-Received: by 2002:a62:8f51:0:b0:4bb:9d8:86cf with SMTP id n78-20020a628f51000000b004bb09d886cfmr66061197pfd.55.1641598069056; Fri, 07 Jan 2022 15:27:49 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id k9sm23343pgr.47.2022.01.07.15.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 15:27:48 -0800 (PST) From: Kees Cook To: Will Deacon Cc: Kees Cook , Peter Zijlstra , Boqun Feng , Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] arm64: atomics: Dereference matching size Date: Fri, 7 Jan 2022 15:27:46 -0800 Message-Id: <20220107232746.1540130-1-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3016; h=from:subject; bh=47ond1j5oGNg2bOUtQPmTXc41W+OJBUy48YiocxEN4U=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBh2MxxvccpCaBRI64wFu4HGOYd1RAGYXBxjWnsjXy5 R2rn/yGJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYdjMcQAKCRCJcvTf3G3AJryvD/ 9sp7vs3pCbVfOzxQ7kLuD+kKELqKNUVCexpGQpaRgthUhlpLMkl4o/uCUdhMl/8vFmoj+trO/gg2ri U2nAztuCZRepyX55YXnD9oP9a91Lj0yUuEC+QBdFqEpzf4vZpWtuzSlVSdvCs0m687FxhhDoOAGrRb DwQeZsnpHSHKCYSr4TXVqXWN/+sU/QjOYShyGXirFcDyJc2oiqfmfwtTcIfjqHHJmWVh2g5bszWkca JJ+8tfXnb25k5CfBP6CX32ltb2OfTUZA5k6PGODdLQoGyR/wstI5izT3Nj6K2CJBLcxiMoxYCzk+jw M1rj0lO4940pou6msREP+yejU4zsqF6asUmFTSDEzr8gSRVyB0ucovrkAwwcd5NA//o2VloyJEgOLz Ie7sP0j0Zo1VAzOGCPOmASBHEGLRHi6yqC9bAsdLLUNCcAArW0M8XKyTptmjQKf3O7nCKh4DrDqyiy KmACPWY5vP6j3FdK94iaYm7JO9QoGbpSLAZ3LQ9L0eOcCmpv29zvGQ7pP2UGCIofiq9my6R+y6WbED 3t0uJb6Ssgy8Y8XVwmakBhmIvA8D2zUuQi80BZcdAO33q9bZDLTSnnoUTDdIESOPH7FqR+9dacRaUF IDbsjMCLcE1xplrSEuaxzIdXt0/59nKJdJaAPohTH59jmZE3FOkOeKr6arEw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220107_152750_670693_058F94E0 X-CRM114-Status: GOOD ( 14.14 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When building with -Warray-bounds (which is desired to be enabled globally), the following warning is generated: In file included from ./arch/arm64/include/asm/lse.h:16, from ./arch/arm64/include/asm/cmpxchg.h:14, from ./arch/arm64/include/asm/atomic.h:16, from ./include/linux/atomic.h:7, from ./include/asm-generic/bitops/atomic.h:5, from ./arch/arm64/include/asm/bitops.h:25, from ./include/linux/bitops.h:33, from ./include/linux/kernel.h:22, from kernel/printk/printk.c:22: ./arch/arm64/include/asm/atomic_lse.h:247:9: warning: array subscript 'long unsigned int[0]' is partly outside array bounds of 'atomic_t[1]' [-Warray-bounds] 247 | asm volatile( \ | ^~~ ./arch/arm64/include/asm/atomic_lse.h:266:1: note: in expansion of macro '__CMPXCHG_CASE' 266 | __CMPXCHG_CASE(w, , acq_, 32, a, "memory") | ^~~~~~~~~~~~~~ kernel/printk/printk.c:3606:17: note: while referencing 'printk_cpulock_owner' 3606 | static atomic_t printk_cpulock_owner = ATOMIC_INIT(-1); | ^~~~~~~~~~~~~~~~~~~~ This is due to the compiler seeing an unsigned long * cast against something (atomic_t) that is int sized. Replace the cast with the matching size cast. This results in no change in binary output. Cc: Will Deacon Cc: Peter Zijlstra Cc: Boqun Feng Cc: Catalin Marinas Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Kees Cook Acked-by: Ard Biesheuvel Acked-by: Mark Rutland --- arch/arm64/include/asm/atomic_lse.h | 2 +- arch/arm64/include/asm/cmpxchg.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/atomic_lse.h b/arch/arm64/include/asm/atomic_lse.h index d955ade5df7c..5d460f6b7675 100644 --- a/arch/arm64/include/asm/atomic_lse.h +++ b/arch/arm64/include/asm/atomic_lse.h @@ -249,7 +249,7 @@ __lse__cmpxchg_case_##name##sz(volatile void *ptr, \ " mov %" #w "[tmp], %" #w "[old]\n" \ " cas" #mb #sfx "\t%" #w "[tmp], %" #w "[new], %[v]\n" \ " mov %" #w "[ret], %" #w "[tmp]" \ - : [ret] "+r" (x0), [v] "+Q" (*(unsigned long *)ptr), \ + : [ret] "+r" (x0), [v] "+Q" (*(u##sz *)ptr), \ [tmp] "=&r" (tmp) \ : [old] "r" (x1), [new] "r" (x2) \ : cl); \ diff --git a/arch/arm64/include/asm/cmpxchg.h b/arch/arm64/include/asm/cmpxchg.h index f9bef42c1411..497acf134d99 100644 --- a/arch/arm64/include/asm/cmpxchg.h +++ b/arch/arm64/include/asm/cmpxchg.h @@ -243,7 +243,7 @@ static inline void __cmpwait_case_##sz(volatile void *ptr, \ " cbnz %" #w "[tmp], 1f\n" \ " wfe\n" \ "1:" \ - : [tmp] "=&r" (tmp), [v] "+Q" (*(unsigned long *)ptr) \ + : [tmp] "=&r" (tmp), [v] "+Q" (*(u##sz *)ptr) \ : [val] "r" (val)); \ }