Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1805665rwb; Thu, 29 Sep 2022 02:27:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6f5mbE4zO3Q1c7Q3+ShKL8LvQFrIG+L1shfGqWfqK98D9i6Mgeo0xBDaxgfEtKYQkFoNIn X-Received: by 2002:a17:907:74e:b0:74f:83d4:cf58 with SMTP id xc14-20020a170907074e00b0074f83d4cf58mr1947945ejb.178.1664443621913; Thu, 29 Sep 2022 02:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664443621; cv=none; d=google.com; s=arc-20160816; b=YBtcJOsgULKlMl/U6+mLspsVVQHLe1opb/o4LIIZdw1dFhfV8e0PLEYuM8F7BYQpct cTLLnNt4k7SwnsCB5gBPqgBxCZoN5DcgH6KOssB0A/RvG+hNabdZEyIpQ0ieH5ySNs1s 1oobJQahBKEGlNJEzotJpC5kG5MU+WFbIbEITsatTFRrY/uKn6z4W91818YuCwuPbyRn AlsZ2Kn05kMBE/uW0kr2OAtR9QmR06/cD/9URvrAAKfGu3mAAOcQC78TvRHIzQ/k9fJJ 2k2OZwFlSohdbuYo1sxBsLjrHtfF4BHeIVMGvPKG6Kpr689EFZtpHH23XtTrF/iyZ1ng YJGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=Zm00l+zmqsCWLK3LqHtfXzxyyxS1KKRiDBtm93jjX9o=; b=C0Rf0bsE047tVW9oKXUAinlJCP865YUIc0E/8S5+7yLWRCtVB7itjkZe+5H7gVm4ce MkqSpSuEt1QCuALmoSqXPb+3otm9daJ/FzzeL5LirMRvtIrRm95awJ/U918AOkvYtkB7 n//u+cyZj2YsPPWFcYo9Qp2cgq0iheSUbQSN0e5wFVXxHAKV85avjWdG/A6XnPudBSu/ JSRxTIKTlsKl0bbTcR1ePOPR9rmTn9kblt0m4tyHLLRxIcNYDWwTPARtEinnYCsthr2+ Sg6xTa31qKUK+xWYHm1TkWhqypjIpxsQumV0SIVT924/cVTYOr9ix4NbOrVmS8Kuj08H NH6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=HvksgIIi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt14-20020a1709072d8e00b0077944aeb944si6882919ejc.742.2022.09.29.02.26.36; Thu, 29 Sep 2022 02:27:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=HvksgIIi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235576AbiI2Igd (ORCPT + 99 others); Thu, 29 Sep 2022 04:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235570AbiI2Igc (ORCPT ); Thu, 29 Sep 2022 04:36:32 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D7E211C16F; Thu, 29 Sep 2022 01:36:21 -0700 (PDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4MdRXW0Bs9z4xGG; Thu, 29 Sep 2022 18:36:11 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1664440575; bh=Zm00l+zmqsCWLK3LqHtfXzxyyxS1KKRiDBtm93jjX9o=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=HvksgIIi1oeSL3sCDaWnCOeWcGonlpaPKJKiI3OtvAu+BHn2yjS8AR76e3Ton4Nmy +EG26HHK0KGq8vBvYX1EeVNsxcIp9mIU6us0cOvxy60zyQiQGRFQuv/txggXaNqN90 ZKWhlWHVgkpzhtZMxMhIP2Bw8oAKyLOzGZWe9yuxbUXzVLSr62mIeEvbWCpkSHrZlO Twy98ZJlAAXDut/ui87OToN2gdrJMOcxFt0qGiH5Q17PEp3FYZEI4DXZJQ30tNXk1t 9aFxJpinn/zEKI8MPHuL3gndj8LsbUTOOq0tZEPF560BHpeqU2OY2AdZ4ghD6NHw5p pKXBKh32qbh6A== From: Michael Ellerman To: Kees Cook , Geert Uytterhoeven Cc: Vlastimil Babka , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Marco Elver , linux-mm@kvack.org, "Ruhl, Michael J" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Greg Kroah-Hartman , Nick Desaulniers , Alex Elder , Josef Bacik , David Sterba , Sumit Semwal , Christian =?utf-8?Q?K=C3=B6nig?= , Jesse Brandeburg , Daniel Micay , Yonghong Song , Miguel Ojeda , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-fsdevel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, dev@openvswitch.org, x86@kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2 01/16] slab: Remove __malloc attribute from realloc functions In-Reply-To: <202209281011.66DD717D@keescook> References: <20220923202822.2667581-1-keescook@chromium.org> <20220923202822.2667581-2-keescook@chromium.org> <202209281011.66DD717D@keescook> Date: Thu, 29 Sep 2022 18:36:05 +1000 Message-ID: <874jwqfuh6.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kees Cook writes: > On Wed, Sep 28, 2022 at 09:26:15AM +0200, Geert Uytterhoeven wrote: >> On Fri, Sep 23, 2022 at 10:35 PM Kees Cook wrote: >> > The __malloc attribute should not be applied to "realloc" functions, as >> > the returned pointer may alias the storage of the prior pointer. Inste= ad >> > of splitting __malloc from __alloc_size, which would be a huge amount = of >> > churn, just create __realloc_size for the few cases where it is needed. >> > >> > Additionally removes the conditional test for __alloc_size__, which is >> > always defined now. >> > >> > Cc: Christoph Lameter >> > Cc: Pekka Enberg >> > Cc: David Rientjes >> > Cc: Joonsoo Kim >> > Cc: Andrew Morton >> > Cc: Vlastimil Babka >> > Cc: Roman Gushchin >> > Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> >> > Cc: Marco Elver >> > Cc: linux-mm@kvack.org >> > Signed-off-by: Kees Cook >>=20 >> Thanks for your patch, which is now commit 63caa04ec60583b1 ("slab: >> Remove __malloc attribute from realloc functions") in next-20220927. >>=20 >> Noreply@ellerman.id.au reported all gcc8-based builds to fail >> (e.g. [1], more at [2]): >>=20 >> In file included from : >> ./include/linux/percpu.h: In function =E2=80=98__alloc_reserved_perc= pu=E2=80=99: >> ././include/linux/compiler_types.h:279:30: error: expected >> declaration specifiers before =E2=80=98__alloc_size__=E2=80=99 >> #define __alloc_size(x, ...) __alloc_size__(x, ## __VA_ARGS__) __ma= lloc >> ^~~~~~~~~~~~~~ >> ./include/linux/percpu.h:120:74: note: in expansion of macro =E2=80= =98__alloc_size=E2=80=99 >> [...] >>=20 >> It's building fine with e.g. gcc-9 (which is my usual m68k cross-compile= r). >> Reverting this commit on next-20220927 fixes the issue. >>=20 >> [1] http://kisskb.ellerman.id.au/kisskb/buildresult/14803908/ >> [2] http://kisskb.ellerman.id.au/kisskb/head/1bd8b75fe6adeaa89d02968bdd8= 11ffe708cf839/ > > Eek! Thanks for letting me know. I'm confused about this -- > __alloc_size__ wasn't optional in compiler_attributes.h -- but obviously > I broke something! I'll go figure this out. This fixes it for me. cheers diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index f141a6f6b9f6..0717534f8364 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -275,8 +275,13 @@ struct ftrace_likely_data { * be performing a _reallocation_, as that may alias the existing pointer. * For these, use __realloc_size(). */ -#define __alloc_size(x, ...) __alloc_size__(x, ## __VA_ARGS__) __malloc -#define __realloc_size(x, ...) __alloc_size__(x, ## __VA_ARGS__) +#ifdef __alloc_size__ +# define __alloc_size(x, ...) __alloc_size__(x, ## __VA_ARGS__) __malloc +# define __realloc_size(x, ...) __alloc_size__(x, ## __VA_ARGS__) +#else +# define __alloc_size(x, ...) __malloc +# define __realloc_size(x, ...) +#endif =20 #ifndef asm_volatile_goto #define asm_volatile_goto(x...) asm goto(x)