Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp812362rwb; Thu, 22 Sep 2022 06:46:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6P4GhlaJF6+seFJPExZOWsew/GKFsP/Pm7OPMWGo8MP4Ev5MBoiRggAcBllN9LKEBUnqg9 X-Received: by 2002:a17:907:9490:b0:781:c079:1294 with SMTP id dm16-20020a170907949000b00781c0791294mr3087366ejc.29.1663854403741; Thu, 22 Sep 2022 06:46:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663854403; cv=none; d=google.com; s=arc-20160816; b=JmaTZDznbwMa9G2/rME8uGSxZtZ/p2I8MfwNx9qORSz+vYm9kZWRP8TKJYAT8Q1lDo z+FpJuq1RriBN5lrZe+2Ctu2dNo1uci3Ht7HIvsGJ3wBuuPHmqJ8bGoFsCKT1OV0Gsdc JL2S+J1uLTPZQSb0I2Qeg853oR3HLBK47K86BCdeJIN52/w+7cmTk5TgCQIzmC+5MM/Q 04zPFMcCsVygYGf5J3xa4E1rYgyxqiwRhWF+Gv+UWvm+vEdjO13F3+Vabp9gJ90/vh/e k+kHyPY3gmOYoGgm2SIJf6aHu9HkNb18aqnaed6FwXZR0G+9ZoBE67EPOjP/ztGXUviS KoDA== 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; bh=lTLxj593wgb0rSkyx/kVpkcZN0XitEmW0vMjErWHotA=; b=Hx/q2JUzKOlegLa+/VY2+EeT5X3wctjKY9Ejyfbt9bWPkbust/MZyBVMPiUSqknBqQ 66hFCMtnD3JXxT6CyMeFTOf4bFApryhjnG+cJZEPjj5UUTXIcFHQdo8v1vUu0CkBvZw1 tSGzbX8hlGp1dYX9eXwJzrD3U64q5KEaMQWpGE7y/BzoghsDzxTZLKkbVMu0727AnAFp VbCy013SpuH+npM6euwSzT5rA1FsZqEnVRrC5mhP5dkcA8ZJ+IJ3xbqy9w34izFj7/PN ZrSJy1ZQgPRS7LHGlIMXcf/2Vb/DMNDBJTIFRScSg6HH/X2txl+iM5PtDoVCFmhrUExU rl+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ieee.org header.s=google header.b=FyJaKv2c; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ieee.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp22-20020a1709073e1600b00780bbe20896si6167843ejc.535.2022.09.22.06.46.26; Thu, 22 Sep 2022 06:46:43 -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=@ieee.org header.s=google header.b=FyJaKv2c; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ieee.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231620AbiIVNph (ORCPT + 63 others); Thu, 22 Sep 2022 09:45:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231383AbiIVNp0 (ORCPT ); Thu, 22 Sep 2022 09:45:26 -0400 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25A523D58D for ; Thu, 22 Sep 2022 06:45:23 -0700 (PDT) Received: by mail-qk1-x733.google.com with SMTP id 3so6156404qka.5 for ; Thu, 22 Sep 2022 06:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ieee.org; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=lTLxj593wgb0rSkyx/kVpkcZN0XitEmW0vMjErWHotA=; b=FyJaKv2cOaRg6P7yvu8zs1jVRm/8RMTbc6dfECJ+ZO5o/HmyZWXx30/9G58nVbrc5b uilHyUda0dD/kYG1qtguthEwDaL9y8JeP+HPCBHfMWclRlKZoOK/NXZxzGUfoaxervvy D0TcePhLr6rEHe3E5Hlf5A5QN/T9th71F+ymU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=lTLxj593wgb0rSkyx/kVpkcZN0XitEmW0vMjErWHotA=; b=jP50iqi8pmMF0A8ACM4LTFkW9yRDmy3pp1cG//msUsdnwjR0H7jvaQPFzZCgJIFE/1 YXf+oWgrc84TJ6bIlF3wNKbFWLj37LDbZU2OykoWBDrh8Z9AxlpIXTIrMWhDUBv+T/nD 9jVyCY687vVzO2OIWlw2VRsA55F/c0Sd0fyKYALmYN/cDJMEbixzMtBzG+/PrIIiEUHb lvN6tXphYLWmzXvdz5JX0duwXVAGeDxkNfY5k/iyub2SzjvPQckgdPD8Dad2AmNPLZJ4 HcQ9UsLJCv61Gn96AG22jN/2TW0jyBgsN+xq7XvfWjlFlFfpRZfAWugoCoesgXQIdC3W DMtQ== X-Gm-Message-State: ACrzQf23LnyixPp/KngyE758ts7kDTXOKbPzLjs9jkTB28QEPcMaaAps y610/Lxb2Di8D7j5oH2hryFWpQ== X-Received: by 2002:a05:620a:f15:b0:6cf:2130:88e3 with SMTP id v21-20020a05620a0f1500b006cf213088e3mr2093263qkl.519.1663854322211; Thu, 22 Sep 2022 06:45:22 -0700 (PDT) Received: from [172.22.22.4] ([98.61.227.136]) by smtp.googlemail.com with ESMTPSA id w7-20020ac857c7000000b0035bbb6268e2sm3902332qta.67.2022.09.22.06.45.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 06:45:21 -0700 (PDT) Message-ID: <4d75a9fd-1b94-7208-9de8-5a0102223e68@ieee.org> Date: Thu, 22 Sep 2022 08:45:19 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 03/12] net: ipa: Proactively round up to kmalloc bucket size Content-Language: en-US To: Kees Cook , Vlastimil Babka Cc: Alex Elder , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Greg Kroah-Hartman , Nick Desaulniers , Josef Bacik , David Sterba , Sumit Semwal , =?UTF-8?Q?Christian_K=c3=b6nig?= , Jesse Brandeburg , Daniel Micay , Yonghong Song , Marco Elver , Miguel Ojeda , Jacob Shin , linux-kernel@vger.kernel.org, linux-mm@kvack.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 References: <20220922031013.2150682-1-keescook@chromium.org> <20220922031013.2150682-4-keescook@chromium.org> From: Alex Elder In-Reply-To: <20220922031013.2150682-4-keescook@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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/21/22 10:10 PM, 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. > > Cc: Alex Elder > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook > --- > drivers/net/ipa/gsi_trans.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c > index 18e7e8c405be..cec968854dcf 100644 > --- a/drivers/net/ipa/gsi_trans.c > +++ b/drivers/net/ipa/gsi_trans.c > @@ -89,6 +89,7 @@ int gsi_trans_pool_init(struct gsi_trans_pool *pool, size_t size, u32 count, > u32 max_alloc) > { > void *virt; > + size_t allocate; I don't care about this but the reverse Christmas tree convention would put the "allocate" variable definition above "virt". Whether you fix that or not, this patch looks good to me. Reviewed-by: Alex Elder > if (!size) > return -EINVAL; > @@ -104,13 +105,15 @@ int gsi_trans_pool_init(struct gsi_trans_pool *pool, size_t size, u32 count, > * If there aren't enough entries starting at the free index, > * we just allocate free entries from the beginning of the pool. > */ > - virt = kcalloc(count + max_alloc - 1, size, GFP_KERNEL); > + allocate = size_mul(count + max_alloc - 1, size); > + allocate = kmalloc_size_roundup(allocate); > + virt = kzalloc(allocate, GFP_KERNEL); > if (!virt) > return -ENOMEM; > > pool->base = virt; > /* If the allocator gave us any extra memory, use it */ > - pool->count = ksize(pool->base) / size; > + pool->count = allocate / size; > pool->free = 0; > pool->max_alloc = max_alloc; > pool->size = size;