Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3899891rdb; Mon, 11 Dec 2023 03:30:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IF95hSj0JGpyDPOXKIk1aCmxiXaCoOvdqeWEjCv8/seyM8m1oQRFAAXdup3sg82ideAAPLA X-Received: by 2002:a05:6358:99a0:b0:16b:fe18:27fc with SMTP id j32-20020a05635899a000b0016bfe1827fcmr5671907rwb.31.1702294204663; Mon, 11 Dec 2023 03:30:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702294204; cv=none; d=google.com; s=arc-20160816; b=DTkCQ/HGQC6BA+LHFDMXn4az3ASVII6t5k08ImH0VjGdatqwc4jht6ccYZmmrOGs2g JLM7M4ZPHG8gTtKgnM1pu6z7KQlZafuEJ1sMjpgwVRWRGPl4RWBHqwakvPL0E1hrad56 coyQRBJU2UmUJPqASIxhtgmPnp21OMN58TaAheodiDIyXICy6AGUMChkxkb3JkgxHlBg uvl+6wojaCwEq44eWvB3xY2eAsATFIzLBlBBB1M+V/OXkHsU1E+ReehWPE1pbKueOwQx l0S4z+9IN3Zzu50PZCi8n90bOQwmISGs479aZk6aIycl0G/qNUHVeEpUNSQ/A7IU02ys wNug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=FP7EHtqWUBZSOsy/PcRUOAuAr5tCg+YAXWgk9Ijm9kI=; fh=otoVflArj3k8OB5YY72G9+9jzL8oXMkwGuOnE3/cHS8=; b=Wr4x5G7I7X9ShZO3sBudNCJd//EUYu+FYa7H4LKHbMfwuCM6iyioB/HRz+rbONvJBt Vgl1+CUtcdSI70MEnBQ7iyCKuUDlgptt0vwkf15TOL2tFnSzLDNGNEkS9gIU1UYVDN2A PMMjkvsUQdOkf5e6AVWynd8UIjWfkccaj77RgP0eI6LWB2Gz4rkupPN6nVu2Y2Zx/Zzu IAAC2pM0ZPHcheZ9Yg32vKf2WB7XAn7jlSt4oTvQKm0HpkI/foLUdqYpefudgLvCrq4j DosDFSNuaNtzvbeM8AnY2zVc2pq49KIYFcICpeBjuNH6IwArlL6F+YYEOsFh0ZbSKTVv BeSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id z20-20020a656654000000b005b8f446408bsi5809006pgv.422.2023.12.11.03.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 03:30:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7861D8073281; Mon, 11 Dec 2023 03:30:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231734AbjLKL3p (ORCPT + 99 others); Mon, 11 Dec 2023 06:29:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbjLKL3n (ORCPT ); Mon, 11 Dec 2023 06:29:43 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B9C4B8; Mon, 11 Dec 2023 03:29:49 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SpffY5cv3z4f3lVy; Mon, 11 Dec 2023 19:29:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id A7C131A0713; Mon, 11 Dec 2023 19:29:46 +0800 (CST) Received: from [10.174.176.117] (unknown [10.174.176.117]) by APP2 (Coremail) with SMTP id Syh0CgBX+0mk8nZlT0rRDQ--.30712S2; Mon, 11 Dec 2023 19:29:44 +0800 (CST) Subject: Re: WARNING: kmalloc bug in bpf_uprobe_multi_link_attach To: xingwei lee , ast@kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org References: From: Hou Tao Message-ID: <689db41e-90f5-c5ba-b690-00586f22d616@huaweicloud.com> Date: Mon, 11 Dec 2023 19:29:40 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID: Syh0CgBX+0mk8nZlT0rRDQ--.30712S2 X-Coremail-Antispam: 1UD129KBjvJXoWxWr1UWr13ur4DWFWkCFyDZFb_yoW7Gryrpr WrJF4YkrW8JryxJF17ta15trZxArZ8C3WDJwsrGFyFvF18WFyjqF4qqw1F9ry5JrWvyr13 tF1DXr4jvr1UW3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvab4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7Mxk0xIA0c2IE e2xFo4CEbIxvr21l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxV Aqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a 6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6x kF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Zr0_Wr1UMIIF0xvEx4A2jsIE 14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyT uYvjxUFDGOUUUUU X-CM-SenderInfo: xkrx3t3r6k3tpzhluzxrxghudrp/ X-Spam-Status: No, score=-3.3 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 11 Dec 2023 03:30:01 -0800 (PST) Hi, On 12/11/2023 4:12 PM, xingwei lee wrote: > Sorry for containing HTML part, repeat the mail > Hello I found a bug in net/bpf in the lastest upstream linux and > lastest net tree. > WARNING: kmalloc bug in bpf_uprobe_multi_link_attach > > kernel: net 28a7cb045ab700de5554193a1642917602787784 > Kernel config: https://github.com/google/syzkaller/commits/fc59b78e3174009510ed15f20665e7ab2435ebee > > in the lastest net tree, the crash like: > > [ 68.363836][ T8223] ------------[ cut here ]------------ > [ 68.364967][ T8223] WARNING: CPU: 2 PID: 8223 at mm/util.c:632 > kvmalloc_node+0x18a/0x1a0 > [ 68.366527][ T8223] Modules linked in: > [ 68.367882][ T8223] CPU: 2 PID: 8223 Comm: 36d Not tainted > 6.7.0-rc4-00146-g28a7cb045ab7 #2 > [ 68.369260][ T8223] Hardware name: QEMU Standard PC (i440FX + PIIX, > 1996), BIOS 1.16.2-1.fc38 04/014 > [ 68.370811][ T8223] RIP: 0010:kvmalloc_node+0x18a/0x1a0 > [ 68.371689][ T8223] Code: dc 1c 00 eb aa e8 86 33 c6 ff 41 81 e4 00 > 20 00 00 31 ff 44 89 e6 e8 e5 20 > [ 68.375001][ T8223] RSP: 0018:ffffc9001088fb68 EFLAGS: 00010293 > [ 68.375989][ T8223] RAX: 0000000000000000 RBX: 00000037ffffcec8 > RCX: ffffffff81c1a32b > [ 68.377154][ T8223] RDX: ffff88802cc00040 RSI: ffffffff81c1a339 > RDI: 0000000000000005 > [ 68.377950][ T8223] RBP: 0000000000000400 R08: 0000000000000005 > R09: 0000000000000000 > [ 68.378744][ T8223] R10: 0000000000000000 R11: 0000000000000000 > R12: 0000000000000000 > [ 68.379523][ T8223] R13: 00000000ffffffff R14: ffff888017eb4a28 > R15: 0000000000000000 > [ 68.380307][ T8223] FS: 0000000000827380(0000) > GS:ffff8880b9900000(0000) knlGS:0000000000000000 > [ 68.381185][ T8223] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > [ 68.381843][ T8223] CR2: 0000000020000140 CR3: 00000000204d2000 > CR4: 0000000000750ef0 > [ 68.382624][ T8223] PKRU: 55555554 > [ 68.382978][ T8223] Call Trace: > [ 68.383312][ T8223] > [ 68.383608][ T8223] ? show_regs+0x8f/0xa0 > [ 68.384052][ T8223] ? __warn+0xe6/0x390 > [ 68.384470][ T8223] ? kvmalloc_node+0x18a/0x1a0 > [ 68.385111][ T8223] ? report_bug+0x3b9/0x580 > [ 68.385585][ T8223] ? handle_bug+0x67/0x90 > [ 68.386032][ T8223] ? exc_invalid_op+0x17/0x40 > [ 68.386503][ T8223] ? asm_exc_invalid_op+0x1a/0x20 > [ 68.387065][ T8223] ? kvmalloc_node+0x17b/0x1a0 > [ 68.387551][ T8223] ? kvmalloc_node+0x189/0x1a0 > [ 68.388051][ T8223] ? kvmalloc_node+0x18a/0x1a0 > [ 68.388537][ T8223] ? kvmalloc_node+0x189/0x1a0 > [ 68.389038][ T8223] bpf_uprobe_multi_link_attach+0x436/0xfb0 It seems a big attr->link_create.uprobe_multi.cnt is passed to bpf_uprobe_multi_link_attach(). Could you please try the first patch in the following patch set ? https://lore.kernel.org/bpf/20231211112843.4147157-1-houtao@huaweicloud.com/T/#t > [ 68.389633][ T8223] ? __might_fault+0x13f/0x1a0 > [ 68.390129][ T8223] ? bpf_kprobe_multi_link_attach+0x10/0x10 SNIP > res = syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x20000140ul, /*size=*/0x90ul); > if (res != -1) r[0] = res; > memcpy((void*)0x20000000, "./file0\000", 8); > syscall(__NR_creat, /*file=*/0x20000000ul, /*mode=*/0ul); > *(uint32_t*)0x20000340 = r[0]; > *(uint32_t*)0x20000344 = 0; > *(uint32_t*)0x20000348 = 0x30; > *(uint32_t*)0x2000034c = 0; > *(uint64_t*)0x20000350 = 0x20000080; > memcpy((void*)0x20000080, "./file0\000", 8); 0x20000350 is the address of attr->link_create.uprobe_multi.path. > *(uint64_t*)0x20000358 = 0x200000c0; > *(uint64_t*)0x200000c0 = 0; > *(uint64_t*)0x20000360 = 0; > *(uint64_t*)0x20000368 = 0; > *(uint32_t*)0x20000370 = 0xffffff1f; The value of attr->link_create.uprobe_multi.cnt is 0xffffff1f, so  0xffffff1f * sizeof(bpf_uprobe) will be greater than INT_MAX, and triggers the warning in mm/util.c:         /* Don't even allow crazy sizes */         if (unlikely(size > INT_MAX)) {                 WARN_ON_ONCE(!(flags & __GFP_NOWARN));                 return NULL;         } Adding __GFP_NOWARN when doing kvcalloc() can fix the warning. > *(uint32_t*)0x20000374 = 0; > *(uint32_t*)0x20000378 = 0; > syscall(__NR_bpf, /*cmd=*/0x1cul, /*arg=*/0x20000340ul, /*size=*/0x40ul); > return 0; > } > > =* repro.txt =* > r0 = bpf$PROG_LOAD(0x5, &(0x7f0000000140)={0x2, 0x3, > &(0x7f0000000200)=@framed, &(0x7f0000000240)='GPL\x00', 0x0, 0x0, 0x0, > 0x0, 0x0, '\x00', 0x0, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, > 0x0, 0x0, 0x0, 0x0, 0x0}, 0x90) > creat(&(0x7f0000000000)='./file0\x00', 0x0) > bpf$BPF_LINK_CREATE_XDP(0x1c, &(0x7f0000000340)={r0, 0x0, 0x30, 0x0, > @val=@uprobe_multi={&(0x7f0000000080)='./file0\x00', > &(0x7f00000000c0)=[0x0], 0x0, 0x0, 0xffffff1f}}, 0x40 > > > See aslo https://gist.github.com/xrivendell7/15d43946c73aa13247b4b20b68798aaa > > .