Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp44930rwb; Thu, 22 Sep 2022 14:10:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Xp0q0yWiFJzYy/3kpL1dMnuz1y7V29ZcO9TBdEv5ghCUWRshUPZE1viMCXlvSzUwviDKr X-Received: by 2002:a17:906:ee89:b0:73d:70c5:1a4e with SMTP id wt9-20020a170906ee8900b0073d70c51a4emr4245426ejb.683.1663881024418; Thu, 22 Sep 2022 14:10:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663881024; cv=none; d=google.com; s=arc-20160816; b=GvA2H/xt8ibp5nmnvo9ud3PB2EOd5LeLMH4TFMW60kJ6/hj21r4KGnElS3q41dXcGJ EtM4LYKeBr+rJ0YXVVNY2TSHjR9zRNw47Dft81+BH+9IWAJQNn9xx2Xlcd2U8tx3n0JB PnEYSTxT2YWlWO4XkO35otWpbTqwJ6cWqJForRiLQObZGTx6+Ju8G+4FBbbcT3+LPUE6 6z3++fsf1+8ZBV1JieMuarD8Xzo40DySJTBI7DyuKHMSutheXrzIV0Qkv1Rgp9pCoDMN QCAZ0HOz5/Aswhaw6OWYYeECcEUqTmE/Y8bXQOS2unZFGXncW065gC3Je1qJWQ5x5gUt HdRQ== 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=XKo+i59z16xYCKZljHHhrwZOK4kULyS2cn+2CLRfUM0=; b=Nz3XrCynOghKoaV3PwfV8K3kuQ4q6RGbdyMsN58ioDhDWLO6KvMiJMbRlUH2Uwc942 FSi+H9XT/6mw4wlnIo63adkUOsbLZ8KQiFnsUBvstuu+Ya58tlwBRLw7ZKx9DBMZZk9M MqHKPzBMbrpY+c70rLgOOTPqLXkoO9fMpeezBLn3zk0vxU2eN0vbDFJaFkQmwZWaR6DB v7dN1I1zn77jQ4JvXrlVCswu7IdSk/3enPYdSo4K81iAUDihKql3gNtSGK6d3Azt/IUU QZO1kngaqRfJA8eZFlLt8rZNYT0T6UfT5Uy6l/ksn42WslQfY8ltjTMW63CTCWphhYE2 1hGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=yYZqXMGx; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 z19-20020a05640240d300b0044eb919cd29si7369503edb.161.2022.09.22.14.09.39; Thu, 22 Sep 2022 14:10:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=yYZqXMGx; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230333AbiIVVFx (ORCPT + 62 others); Thu, 22 Sep 2022 17:05:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbiIVVFu (ORCPT ); Thu, 22 Sep 2022 17:05:50 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC2A310CA5F; Thu, 22 Sep 2022 14:05:49 -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 4788F1F8BD; Thu, 22 Sep 2022 21:05:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1663880748; 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=XKo+i59z16xYCKZljHHhrwZOK4kULyS2cn+2CLRfUM0=; b=yYZqXMGxzMVH0hLKeYU8DtcEW5z+72E8D8wluVkMB38JNQ6mVtvWYW44sf9Qr+ZQm+We5X ZxoqRMYTP+O1T/rNawICmYwKgqmViLi4WF8AuUeX1BOp9TwGPEwvLg1O9HhwZMa65TkR9W yGHcw9EwWtJmQERB8NRzG2kYdmwST+U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1663880748; 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=XKo+i59z16xYCKZljHHhrwZOK4kULyS2cn+2CLRfUM0=; b=kaD9JOgsDV+IpQlfyoPslHKu+574Yw//haDJvp79fZBtXqIgPNRCscY2PniCUaAEZMnwWD sPWSH1zmuGYRGABQ== 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 B86DF1346B; Thu, 22 Sep 2022 21:05:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QI4BLCvOLGP2JwAAMHmgww (envelope-from ); Thu, 22 Sep 2022 21:05:47 +0000 Message-ID: Date: Thu, 22 Sep 2022 23:05:47 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH 00/12] slab: Introduce kmalloc_size_roundup() Content-Language: en-US To: Kees Cook , =?UTF-8?Q?Christian_K=c3=b6nig?= Cc: Pekka Enberg , Feng Tang , David Rientjes , Joonsoo Kim , Andrew Morton , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Greg Kroah-Hartman , Nick Desaulniers , Alex Elder , Josef Bacik , David Sterba , Sumit Semwal , Jesse Brandeburg , Daniel Micay , Yonghong Song , Marco Elver , Miguel Ojeda , linux-kernel@vger.kernel.org, linux-mm@kvack.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, linux-wireless@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, Hyeonggon Yoo <42.hyeyoo@gmail.com>, Feng Tang References: <20220922031013.2150682-1-keescook@chromium.org> <673e425d-1692-ef47-052b-0ff2de0d9c1d@amd.com> <202209220845.2F7A050@keescook> From: Vlastimil Babka In-Reply-To: <202209220845.2F7A050@keescook> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,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-wireless@vger.kernel.org On 9/22/22 17:55, Kees Cook wrote: > On Thu, Sep 22, 2022 at 09:10:56AM +0200, Christian König wrote: >> Am 22.09.22 um 05:10 schrieb Kees Cook: >> > Hi, >> > >> > This series fixes up the cases where callers of ksize() use it to >> > opportunistically grow their buffer sizes, which can run afoul of the >> > __alloc_size hinting that CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE >> > use to perform dynamic buffer bounds checking. >> >> Good cleanup, but one question: What other use cases we have for ksize() >> except the opportunistically growth of buffers? > > The remaining cases all seem to be using it as a "do we need to resize > yet?" check, where they don't actually track the allocation size > themselves and want to just depend on the slab cache to answer it. This > is most clearly seen in the igp code: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/intel/igb/igb_main.c?h=v6.0-rc6#n1204 > > My "solution" there kind of side-steps it, and leaves ksize() as-is: > https://lore.kernel.org/linux-hardening/20220922031013.2150682-8-keescook@chromium.org/ > > The more correct solution would be to add per-v_idx size tracking, > similar to the other changes I sent: > https://lore.kernel.org/linux-hardening/20220922031013.2150682-11-keescook@chromium.org/ > > I wonder if perhaps I should just migrate some of this code to using > something like struct membuf. > >> Off hand I can't see any. >> >> So when this patch set is about to clean up this use case it should probably >> also take care to remove ksize() or at least limit it so that it won't be >> used for this use case in the future. > > Yeah, my goal would be to eliminate ksize(), and it seems possible if > other cases are satisfied with tracking their allocation sizes directly. I think we could leave ksize() to determine the size without a need for external tracking, but from now on forbid callers from using that hint to overflow the allocation size they actually requested? Once we remove the kasan/kfence hooks in ksize() that make the current kinds of usage possible, we should be able to catch any offenders of the new semantics that would appear? > -Kees >