{"id":1839977,"url":"http://patchwork.ozlabs.org/api/patches/1839977/?format=json","web_url":"http://patchwork.ozlabs.org/project/ubuntu-kernel/patch/20230927004025.119111-5-cascardo@canonical.com/","project":{"id":15,"url":"http://patchwork.ozlabs.org/api/projects/15/?format=json","name":"Ubuntu Kernel","link_name":"ubuntu-kernel","list_id":"kernel-team.lists.ubuntu.com","list_email":"kernel-team@lists.ubuntu.com","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20230927004025.119111-5-cascardo@canonical.com>","list_archive_url":null,"date":"2023-09-27T00:40:24","name":"[SRU,OEM-6.1,Lunar,4/5] net: factorize code in kmalloc_reserve()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"92b32184efb0c9012a71805d933da776882f8853","submitter":{"id":70574,"url":"http://patchwork.ozlabs.org/api/people/70574/?format=json","name":"Thadeu Lima de Souza Cascardo","email":"cascardo@canonical.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/ubuntu-kernel/patch/20230927004025.119111-5-cascardo@canonical.com/mbox/","series":[{"id":375017,"url":"http://patchwork.ozlabs.org/api/series/375017/?format=json","web_url":"http://patchwork.ozlabs.org/project/ubuntu-kernel/list/?series=375017","date":"2023-09-27T00:40:20","name":"CVE-2023-42752","version":1,"mbox":"http://patchwork.ozlabs.org/series/375017/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/1839977/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/1839977/checks/","tags":{},"related":[],"headers":{"Return-Path":"<kernel-team-bounces@lists.ubuntu.com>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":"legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com\n (client-ip=185.125.189.65; helo=lists.ubuntu.com;\n envelope-from=kernel-team-bounces@lists.ubuntu.com;\n receiver=patchwork.ozlabs.org)","Received":["from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4RwHpg5G7rz1ypS\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 27 Sep 2023 10:40:59 +1000 (AEST)","from localhost ([127.0.0.1] helo=lists.ubuntu.com)\n\tby lists.ubuntu.com with esmtp (Exim 4.86_2)\n\t(envelope-from <kernel-team-bounces@lists.ubuntu.com>)\n\tid 1qlIbh-0004iR-L5; Wed, 27 Sep 2023 00:40:49 +0000","from smtp-relay-canonical-0.internal ([10.131.114.83]\n helo=smtp-relay-canonical-0.canonical.com)\n by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.86_2) (envelope-from <cascardo@canonical.com>)\n id 1qlIbb-0004dv-Am\n for kernel-team@lists.ubuntu.com; Wed, 27 Sep 2023 00:40:43 +0000","from quatroqueijos.lan (1.general.cascardo.us.vpn [10.172.70.58])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 278F53F123\n for <kernel-team@lists.ubuntu.com>; Wed, 27 Sep 2023 00:40:41 +0000 (UTC)"],"From":"Thadeu Lima de Souza Cascardo <cascardo@canonical.com>","To":"kernel-team@lists.ubuntu.com","Subject":"[SRU OEM-6.1,Lunar 4/5] net: factorize code in kmalloc_reserve()","Date":"Tue, 26 Sep 2023 21:40:24 -0300","Message-Id":"<20230927004025.119111-5-cascardo@canonical.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20230927004025.119111-1-cascardo@canonical.com>","References":"<20230927004025.119111-1-cascardo@canonical.com>","MIME-Version":"1.0","X-BeenThere":"kernel-team@lists.ubuntu.com","X-Mailman-Version":"2.1.20","Precedence":"list","List-Id":"Kernel team discussions <kernel-team.lists.ubuntu.com>","List-Unsubscribe":"<https://lists.ubuntu.com/mailman/options/kernel-team>,\n <mailto:kernel-team-request@lists.ubuntu.com?subject=unsubscribe>","List-Archive":"<https://lists.ubuntu.com/archives/kernel-team>","List-Post":"<mailto:kernel-team@lists.ubuntu.com>","List-Help":"<mailto:kernel-team-request@lists.ubuntu.com?subject=help>","List-Subscribe":"<https://lists.ubuntu.com/mailman/listinfo/kernel-team>,\n <mailto:kernel-team-request@lists.ubuntu.com?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"kernel-team-bounces@lists.ubuntu.com","Sender":"\"kernel-team\" <kernel-team-bounces@lists.ubuntu.com>"},"content":"From: Eric Dumazet <edumazet@google.com>\n\nAll kmalloc_reserve() callers have to make the same computation,\nwe can factorize them, to prepare following patch in the series.\n\nSigned-off-by: Eric Dumazet <edumazet@google.com>\nAcked-by: Soheil Hassas Yeganeh <soheil@google.com>\nAcked-by: Paolo Abeni <pabeni@redhat.com>\nReviewed-by: Alexander Duyck <alexanderduyck@fb.com>\nSigned-off-by: Jakub Kicinski <kuba@kernel.org>\n(cherry picked from commit 5c0e820cbbbe2d1c4cea5cd2bfc1302c123436df)\nCVE-2023-42752\nSigned-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>\n---\n net/core/skbuff.c | 27 +++++++++++----------------\n 1 file changed, 11 insertions(+), 16 deletions(-)","diff":"diff --git a/net/core/skbuff.c b/net/core/skbuff.c\nindex 94444244dc16..7219fb97a560 100644\n--- a/net/core/skbuff.c\n+++ b/net/core/skbuff.c\n@@ -479,17 +479,20 @@ EXPORT_SYMBOL(napi_build_skb);\n  * may be used. Otherwise, the packet data may be discarded until enough\n  * memory is free\n  */\n-static void *kmalloc_reserve(size_t size, gfp_t flags, int node,\n+static void *kmalloc_reserve(unsigned int *size, gfp_t flags, int node,\n \t\t\t     bool *pfmemalloc)\n {\n-\tvoid *obj;\n \tbool ret_pfmemalloc = false;\n+\tunsigned int obj_size;\n+\tvoid *obj;\n \n+\tobj_size = SKB_HEAD_ALIGN(*size);\n+\t*size = obj_size = kmalloc_size_roundup(obj_size);\n \t/*\n \t * Try a regular allocation, when that fails and we're not entitled\n \t * to the reserves, fail.\n \t */\n-\tobj = kmalloc_node_track_caller(size,\n+\tobj = kmalloc_node_track_caller(obj_size,\n \t\t\t\t\tflags | __GFP_NOMEMALLOC | __GFP_NOWARN,\n \t\t\t\t\tnode);\n \tif (obj || !(gfp_pfmemalloc_allowed(flags)))\n@@ -497,7 +500,7 @@ static void *kmalloc_reserve(size_t size, gfp_t flags, int node,\n \n \t/* Try again but now we are using pfmemalloc reserves */\n \tret_pfmemalloc = true;\n-\tobj = kmalloc_node_track_caller(size, flags, node);\n+\tobj = kmalloc_node_track_caller(obj_size, flags, node);\n \n out:\n \tif (pfmemalloc)\n@@ -558,9 +561,7 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,\n \t * aligned memory blocks, unless SLUB/SLAB debug is enabled.\n \t * Both skb->head and skb_shared_info are cache line aligned.\n \t */\n-\tsize = SKB_HEAD_ALIGN(size);\n-\tsize = kmalloc_size_roundup(size);\n-\tdata = kmalloc_reserve(size, gfp_mask, node, &pfmemalloc);\n+\tdata = kmalloc_reserve(&size, gfp_mask, node, &pfmemalloc);\n \tif (unlikely(!data))\n \t\tgoto nodata;\n \t/* kmalloc_size_roundup() might give us more room than requested.\n@@ -1896,9 +1897,7 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,\n \tif (skb_pfmemalloc(skb))\n \t\tgfp_mask |= __GFP_MEMALLOC;\n \n-\tsize = SKB_HEAD_ALIGN(size);\n-\tsize = kmalloc_size_roundup(size);\n-\tdata = kmalloc_reserve(size, gfp_mask, NUMA_NO_NODE, NULL);\n+\tdata = kmalloc_reserve(&size, gfp_mask, NUMA_NO_NODE, NULL);\n \tif (!data)\n \t\tgoto nodata;\n \tsize = SKB_WITH_OVERHEAD(size);\n@@ -6256,9 +6255,7 @@ static int pskb_carve_inside_header(struct sk_buff *skb, const u32 off,\n \tif (skb_pfmemalloc(skb))\n \t\tgfp_mask |= __GFP_MEMALLOC;\n \n-\tsize = SKB_HEAD_ALIGN(size);\n-\tsize = kmalloc_size_roundup(size);\n-\tdata = kmalloc_reserve(size, gfp_mask, NUMA_NO_NODE, NULL);\n+\tdata = kmalloc_reserve(&size, gfp_mask, NUMA_NO_NODE, NULL);\n \tif (!data)\n \t\treturn -ENOMEM;\n \tsize = SKB_WITH_OVERHEAD(size);\n@@ -6374,9 +6371,7 @@ static int pskb_carve_inside_nonlinear(struct sk_buff *skb, const u32 off,\n \tif (skb_pfmemalloc(skb))\n \t\tgfp_mask |= __GFP_MEMALLOC;\n \n-\tsize = SKB_HEAD_ALIGN(size);\n-\tsize = kmalloc_size_roundup(size);\n-\tdata = kmalloc_reserve(size, gfp_mask, NUMA_NO_NODE, NULL);\n+\tdata = kmalloc_reserve(&size, gfp_mask, NUMA_NO_NODE, NULL);\n \tif (!data)\n \t\treturn -ENOMEM;\n \tsize = SKB_WITH_OVERHEAD(size);\n","prefixes":["SRU","OEM-6.1","Lunar","4/5"]}