Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7289969rwi; Mon, 24 Oct 2022 12:26:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4JdcLK7TSe2UP6fccRXuoNT68SaZ549gjiowCQela3OGoIH5uLiMaSVMhy9Wn+7D8N56P2 X-Received: by 2002:a17:907:2d89:b0:78d:9c30:452b with SMTP id gt9-20020a1709072d8900b0078d9c30452bmr27508316ejc.533.1666639560493; Mon, 24 Oct 2022 12:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666639560; cv=none; d=google.com; s=arc-20160816; b=mgNHHLswdFSqvPzFbY4inkqZQTg0qZnLhPpYmPJEqrAvVzWzbp+/qLBYXXdRdPVo8g iqP7cnnD0K5tL5dX/SlHDeDRK4y5SgJKtmXAUsLpvVPDN2jEJZuCp/RNGfLhEFIdmDEQ rEeZuVxru8YBqqrbxcLslfXomJru9X28BftOKXKAbuR4jWjtwEizRHTomZ4bdkItEdmk V74ZvcV9XED7SE5WpP2pUtGt9sd7lqo3D5dothuwMI7BDwVvpzBnNpvnc27rVmZldb6P 9XGwaUSE72fFyfsQMincwMW1qWdbXzEN72X0dCtNGUI2iEeO0VyvWmCw4kXbVEjFt4Fj iWxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=/4AsP2lH5VLRlMfCDU8gypauekMVyVorINlnPMIld2U=; b=T0zaF0ky66tGSQC8Yt5bwyyi907C8OWI50RUs2CbdCfdGMqUnJPz2bdR3zauL9Ug6a elwGUp8MkNuSL3DYZzo5jhqbJrchmNMi46Xs9BwcL2f7t3tPOjv8ciDW07TGgKM5k71N xc5rD7jMRNMA9C6bE6n+LxrctUBDsLmPtVndrwYKkp1Jb3I/AofPQ9z+MfjjpUV1Z4a1 ZxrFXxFbpKF+ry3Gn464UjPveGyFjNlzXxSGEROXL4MjAf0foY4/36j7wsp9MY+AC2dN /o2n8v/DmUtzvoCvIkZUR8zA1ePhPDQNOVSOM88RCvFsEZ088tVXJ88ICaAC0pVatKQv n3pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=NwYY16UV; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 s18-20020a056402521200b0045ca15afe1csi515787edd.553.2022.10.24.12.25.33; Mon, 24 Oct 2022 12:26:00 -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=@suse.cz header.s=susede2_rsa header.b=NwYY16UV; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 S231642AbiJXTV4 (ORCPT + 99 others); Mon, 24 Oct 2022 15:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231206AbiJXTU6 (ORCPT ); Mon, 24 Oct 2022 15:20:58 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C5612DAB7; Mon, 24 Oct 2022 10:56:42 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F339D1FDA7; Mon, 24 Oct 2022 17:56:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1666634166; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/4AsP2lH5VLRlMfCDU8gypauekMVyVorINlnPMIld2U=; b=NwYY16UVbu0Qf9CD5Uf4XGmdYIdwelYRbEAYjhqsDilgO2tetDQdlOE+5nkt50vXfPLrCC IQ0zVd4V122Oyq5G5yp9b/f/VDlm7L7fBTpoBLfj0TW+bYbmxUVjwijSqf/I6mmrwhESIc 208fQlSQ0MM3C2R3NcCKcSjSuWpVNTM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1666634166; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/4AsP2lH5VLRlMfCDU8gypauekMVyVorINlnPMIld2U=; b=UNKXMSF60pToCIgoUKZ5sgBRBY89POUDW/+xz3htk59YQWXppXxCDsNsKfLiPdbCE/qV/G E5S/5pRictJz5FAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C1D0813357; Mon, 24 Oct 2022 17:56:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cH6CLrXRVmOmEAAAMHmgww (envelope-from ); Mon, 24 Oct 2022 17:56:05 +0000 Message-ID: Date: Mon, 24 Oct 2022 19:56:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH v4] skbuff: Proactively round up to kmalloc bucket size Content-Language: en-US To: Kees Cook , "David S. Miller" Cc: Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, Greg Kroah-Hartman , Nick Desaulniers , David Rientjes , Pavel Begunkov , Menglong Dong , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20221021234713.you.031-kees@kernel.org> From: Vlastimil Babka In-Reply-To: <20221021234713.you.031-kees@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_SOFTFAIL 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 On 10/22/22 01:49, Kees Cook wrote: > Instead of discovering the kmalloc bucket size _after_ allocation, round > up proactively so the allocation is explicitly made for the full size, > allowing the compiler to correctly reason about the resulting size of > the buffer through the existing __alloc_size() hint. > > This will allow for kernels built with CONFIG_UBSAN_BOUNDS or the > coming dynamic bounds checking under CONFIG_FORTIFY_SOURCE to gain > back the __alloc_size() hints that were temporarily reverted in commit > 93dd04ab0b2b ("slab: remove __alloc_size attribute from __kmalloc_track_caller") > > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: netdev@vger.kernel.org > Cc: Greg Kroah-Hartman > Cc: Nick Desaulniers > Cc: David Rientjes > Cc: Vlastimil Babka > Signed-off-by: Kees Cook Acked-by: Vlastimil Babka Nit below: > --- > v4: use kmalloc_size_roundup() in callers, not kmalloc_reserve() > v3: https://lore.kernel.org/lkml/20221018093005.give.246-kees@kernel.org > v2: https://lore.kernel.org/lkml/20220923202822.2667581-4-keescook@chromium.org > --- > net/core/skbuff.c | 50 +++++++++++++++++++++++------------------------ > 1 file changed, 25 insertions(+), 25 deletions(-) > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > index 651a82d30b09..77af430296e2 100644 > --- a/net/core/skbuff.c > +++ b/net/core/skbuff.c > @@ -508,14 +508,14 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, > */ > size = SKB_DATA_ALIGN(size); > size += SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); > - data = kmalloc_reserve(size, gfp_mask, node, &pfmemalloc); > + osize = kmalloc_size_roundup(size); > + data = kmalloc_reserve(osize, gfp_mask, node, &pfmemalloc); > if (unlikely(!data)) > goto nodata; > /* kmalloc(size) might give us more room than requested. The line above should now say kmalloc_size_roundup(size), or maybe could be deleted completely now? > * Put skb_shared_info exactly at the end of allocated zone, > * to allow max possible filling before reallocation. > */ > - osize = ksize(data); > size = SKB_WITH_OVERHEAD(osize); > prefetchw(data + size); >