From mboxrd@z Thu Jan 1 00:00:00 1970 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 D2DCCC433F5 for ; Wed, 12 Jan 2022 20:20:24 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tVhkpGUhGqYKuuI8cXYRWau3yQ+i0q2FHVr8xz0CRpw=; b=Pg3c5Xam6sf8G9 9QjT5iPsdGCEvjazMkLeS9OqHat7zuIhSM8kk7PSLy1UGfAF0VA+of/a+N1lfmAGcQmnfJA+0PpBw QINJShJIMRLIxpAEvxKa8CONUDFgjcCcEoimnR48hZXpRLmItsHzOpNzm7uGpyRVLtEw80qNXLn3u HEBgxq723o+lJ/j1U98yAlr72JP3bSnD9SmmPJhY8T6hL2JLcLbfrPvXI1mohlpaTgLTJi+MZC62R j3/aKih7awG/0JkmQUj4Bi3VQB5I2WmvkgoznE15NCt57mfQNyyEZOmitt6mAV9UajCXHB+2FxJ/x +C6lr85u+BWPjy0u6iSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7k5K-003io2-Vb; Wed, 12 Jan 2022 20:19:07 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7k5H-003imO-Gy for linux-arm-kernel@lists.infradead.org; Wed, 12 Jan 2022 20:19:05 +0000 Received: by mail-pl1-x629.google.com with SMTP id t18so5815848plg.9 for ; Wed, 12 Jan 2022 12:18:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=cWg9oGmX5VjzwBIpzlyYG0aMpDjKGVxhDdmjr+TTfSE=; b=Wvl5veJvVOxAEEqXRfAlq3EFmvwi1k+5HEmL903UUIkAXm0sRZlwm/KBWwfxggotD9 nSE2A51iCWC2SwhO0m7e4BYIOh/W7C/TOBh1bCV/0MEuwdfnL0c2cAijoGKgBa+t9wYA 3zA/m12UZ+/zfgcxV00ab7JXCYBA8/HQXZKN4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=cWg9oGmX5VjzwBIpzlyYG0aMpDjKGVxhDdmjr+TTfSE=; b=fk2g2ZCSpvZUDEeHd2dCI6WmewF0UxuK1qhSylI6tDGu6du5owFbTyshrUroZVLM/V UhQe//f/R71UvEniGsnB2MMTtCAk/jTlEiRLC+sXGxdeGkENKeAKKvRB/NEpA3PmIfSJ HHgcXyZv/nwZS760KFgOGHBxSEyFo9A8A9nkeso06zs1u7XinNrxtgypFdEdTxl+5oM3 y2VY9YfhSOUceIRF5P3tzjyrDJVSTjQ4Wmn7iAPxNTGsJ77J4ZqiA3DZ2ypOrkAD7c08 8heHWj/10obzUr2taRP4qFVa7uKUSZv99GUetdbgnlbR+4qy4KBYsa7Cxn8jE6l74oGL Q/rA== X-Gm-Message-State: AOAM5322RJH48BLsMhKGhWjFMGGJbCufZD6FOM6W0MRIKG8sQ8S7baJy VehVS3zmGVk2TKvKtPTmFViCdw== X-Google-Smtp-Source: ABdhPJxO2Q9IGXVDG75qeMUDFvdczT7RHBGhaxNrz76IxGxWNBohSOWl8G2Wtv7gTZPEKYr34aTyVA== X-Received: by 2002:aa7:8592:0:b0:4be:2691:bb88 with SMTP id w18-20020aa78592000000b004be2691bb88mr1214917pfn.20.1642018739352; Wed, 12 Jan 2022 12:18:59 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x25sm422555pfu.113.2022.01.12.12.18.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 12:18:59 -0800 (PST) Date: Wed, 12 Jan 2022 12:18:58 -0800 From: Kees Cook To: Mark Rutland Cc: Will Deacon , Peter Zijlstra , Boqun Feng , Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] arm64: atomics: Dereference matching size Message-ID: <202201121217.FB408C2362@keescook> References: <20220107232746.1540130-1-keescook@chromium.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220112_121903_608742_31AF3A15 X-CRM114-Status: GOOD ( 29.41 ) 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 On Mon, Jan 10, 2022 at 10:27:59AM +0000, Mark Rutland wrote: > Hi Kees, > > On Fri, Jan 07, 2022 at 03:27:46PM -0800, Kees Cook wrote: > > 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. > > Just to check, I assume both GCC and Clang are happy with this applied? > > I recall that (historically at least) clang would warn about size mismatches > for inline assembly and would sometimes require more care. I don't see anythign > for which that would matter, but I just want to check. Yup, Clang is happy with this AFAICT. > > > Cc: Will Deacon > > Cc: Peter Zijlstra > > Cc: Boqun Feng > > Cc: Catalin Marinas > > Cc: linux-arm-kernel@lists.infradead.org > > Signed-off-by: Kees Cook > > --- > > 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); \ > > It might be worth nothing that __ll_sc__cmpxchg_case_##name##sz already uses > the same constraint: > > [v] "+Q" (*(u##sz *)ptr > > ... since that explains why we only need to update the LSE form and not the > LL/SC form, and indicates that this is unlikely to be problematic. Good idea, I'll note that in a v2. > > Either way: > > Acked-by: Mark Rutland Thanks! -Kees > > Thanks, > Mark. > > > 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)); \ > > } > > > > -- > > 2.30.2 > > -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel