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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 582ABC32771 for ; Mon, 26 Sep 2022 09:29:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4F0B8E0038; Mon, 26 Sep 2022 05:29:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFE8F6B007E; Mon, 26 Sep 2022 05:29:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99F7E8E0038; Mon, 26 Sep 2022 05:29:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 81B856B007B for ; Mon, 26 Sep 2022 05:29:26 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4F2F012077C for ; Mon, 26 Sep 2022 09:29:26 +0000 (UTC) X-FDA: 79953713532.01.3D092B5 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by imf04.hostedemail.com (Postfix) with ESMTP id F06A04000A for ; Mon, 26 Sep 2022 09:29:25 +0000 (UTC) Received: by mail-ed1-f54.google.com with SMTP id u24so8132003edb.9 for ; Mon, 26 Sep 2022 02:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=RRTzEh4eX7QJuMr9PBYcSE6qe2YnKNQ4s+EeI3ZLOR8=; b=N2CdQZ5DidOd7rXorrAHwsU7REyGYjsVLRQw24k5i/zVnwxTVLXi79SokmwMPQ23dG ltHADiZ2Xdl1ZpGJHcq9sCz91HuEiXsn5cgUkN6cCcc0qhs3gJdO6JtWSNxOVKAm2maA RUP45w5trMH4BmzGD7P4bYWDoQ80fJ5gk/tTcqUWNZwxEVqilkjzRE/DXJj2o9eLrnMT Eibb/G/CFzTjUYyiTkzjs9+xpKaddZrQr2Ady4gPnOt6q/+8sfnBsKlTNnNA0nWB58c5 OZTJtHQ5pIa7jnF722Q6qFBJveO3Wd9eH06jY4XW0T30bgmjP4abl+o8prFN+WFIDcbp QH5w== 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=RRTzEh4eX7QJuMr9PBYcSE6qe2YnKNQ4s+EeI3ZLOR8=; b=3KjzhFWCWK2Q/C3CeexYvDREJ0u97TVh5lHV5Di8z+eKcvIq7U7VD6FJLLNSqkiNk2 h0Ful7hNCWO/0N9q3dDIhNJmds3/rasFasKeURkuMMVdz688B7I7pHFUDQkURL3KCCY4 9ZFbbDPDlOSW3bnarUWXLOa1xQcKsE3SrhhdpKtvK3Dt1IJ5azdLh8QG3JuTbcaVlEaI 2yE0SH9eYE9NpCg7BXKi68gn3oVD+hEfG8O5asFHyNJ+atx2+rz02Uv5J5Ods6m+y9fh LfObkEj1bvzYrM0wGmv2H1BLiP1RttmvvC0KZR6l/Ryt5MYSbm+8BN0t+PjI0wZc2EF9 vDQg== X-Gm-Message-State: ACrzQf1Sq325PdxYI7f9zATnrxTxINd8ejqogUYGGt1OUw/KbTZETKdG KgSsTg4SBMn2Y8mTZkIZX78= X-Google-Smtp-Source: AMsMyM7SuVBgSYWy5kh1HhAcVXy6Llss6obNUjIA/ZoXJgkE8T8RGaoTb9VPoRu5QX3Pg6i6kN2O6A== X-Received: by 2002:a05:6402:2489:b0:454:11de:7698 with SMTP id q9-20020a056402248900b0045411de7698mr21490387eda.214.1664184564514; Mon, 26 Sep 2022 02:29:24 -0700 (PDT) Received: from [192.168.178.21] (p4fc20ebf.dip0.t-ipconnect.de. [79.194.14.191]) by smtp.gmail.com with ESMTPSA id lh3-20020a170906f8c300b00782ee6b34f2sm3710039ejb.183.2022.09.26.02.29.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Sep 2022 02:29:24 -0700 (PDT) Message-ID: Date: Mon, 26 Sep 2022 11:29:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [Linaro-mm-sig] [PATCH v2 08/16] dma-buf: Proactively round up to kmalloc bucket size Content-Language: en-US To: Kees Cook , Vlastimil Babka Cc: Sumit Semwal , =?UTF-8?Q?Christian_K=c3=b6nig?= , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, "Ruhl, Michael J" , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Christoph Lameter , Pekka Enberg , 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 , Jesse Brandeburg , Daniel Micay , Yonghong Song , Marco Elver , Miguel Oj eda , linux-kernel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-btrfs@vger.kernel.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 References: <20220923202822.2667581-1-keescook@chromium.org> <20220923202822.2667581-9-keescook@chromium.org> From: =?UTF-8?Q?Christian_K=c3=b6nig?= In-Reply-To: <20220923202822.2667581-9-keescook@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=N2CdQZ5D; spf=pass (imf04.hostedemail.com: domain of ckoenig.leichtzumerken@gmail.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=ckoenig.leichtzumerken@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664184565; a=rsa-sha256; cv=none; b=guosDpiN2K2UD6VZXh2uREbpTg3R8Gghpk4TdQbAc+qvR+BjDWH9CLNGpZVvf2rlSb7yMb M8++g6Fr6B5FGhsxSGPH9gbep+n+Hf/WslWBX3/iN8MwS1o/nwoUEasuAkp6bUelGpmh7j QbISP6J/knoiGI1XopTsdBcVURKxlV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664184565; h=from:from:sender:reply-to:subject:subject: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:dkim-signature; bh=RRTzEh4eX7QJuMr9PBYcSE6qe2YnKNQ4s+EeI3ZLOR8=; b=1OS5kwGTS72T8ae10lA5k7PjzI9nGuYA9b0IiEb3q9NEXWs1MJickbCAyI5EPhtW5jqS++ gDNrhG7Uc6G568bKChhv6QoYzgIKbpl3OG1q6Mu0PdzsX5fp5BtARKBlP9TfKyQEoSA4/S sD4lf/QNI4jfdfuAI88rZV1avLBaM3A= X-Stat-Signature: 9ree4866cqoiezbn3j3fjju4k4787kpn X-Rspamd-Queue-Id: F06A04000A Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=N2CdQZ5D; spf=pass (imf04.hostedemail.com: domain of ckoenig.leichtzumerken@gmail.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=ckoenig.leichtzumerken@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1664184565-368955 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Am 23.09.22 um 22:28 schrieb Kees Cook: > 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: Sumit Semwal > Cc: "Christian König" > Cc: linux-media@vger.kernel.org > Cc: dri-devel@lists.freedesktop.org > Cc: linaro-mm-sig@lists.linaro.org > Signed-off-by: Kees Cook Reviewed-by: Christian König > --- > drivers/dma-buf/dma-resv.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c > index 205acb2c744d..5b0a4b8830ff 100644 > --- a/drivers/dma-buf/dma-resv.c > +++ b/drivers/dma-buf/dma-resv.c > @@ -98,12 +98,17 @@ static void dma_resv_list_set(struct dma_resv_list *list, > static struct dma_resv_list *dma_resv_list_alloc(unsigned int max_fences) > { > struct dma_resv_list *list; > + size_t size; > > - list = kmalloc(struct_size(list, table, max_fences), GFP_KERNEL); > + /* Round up to the next kmalloc bucket size. */ > + size = kmalloc_size_roundup(struct_size(list, table, max_fences)); > + > + list = kmalloc(size, GFP_KERNEL); > if (!list) > return NULL; > > - list->max_fences = (ksize(list) - offsetof(typeof(*list), table)) / > + /* Given the resulting bucket size, recalculated max_fences. */ > + list->max_fences = (size - offsetof(typeof(*list), table)) / > sizeof(*list->table); > > return list;