Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4943487rwi; Mon, 17 Oct 2022 13:04:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM54e9ROlV5UR9atOvY1WY2oQ05nPH003kpw5E8BzNJFz0zDt9x6F3gq6ofahrRYvXL8gUyq X-Received: by 2002:a17:903:2306:b0:185:43a2:3d1c with SMTP id d6-20020a170903230600b0018543a23d1cmr13665961plh.154.1666037058542; Mon, 17 Oct 2022 13:04:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666037058; cv=none; d=google.com; s=arc-20160816; b=C7oCIqlJ5FugEfgFEyIdF2BTbrH8CMXYpWOTOvBsCsZ/PHdkTJHyXD6un3whRHDG26 WAbdwmbHY1VCkxuS5Ixsig3ct0N25Sq6muT6bsBcObVE/dF4vgOo3rUoyvAKVmvfZQdJ yyP8bWm7vvY/fe10EUZErto7Er+061EV/5/DdAZrnf81WfH7Th8/Vo/0ZO3RyA0dK2KP GfFC/bcfKMyflGD9qyy97jUrLha4H7Sxc2QrqEitPOv6cnJLb03VO2uUjvQQr1tzbO0d eXMsQGsfsbRH0ITufSgEU3I+AYh/aryunyDB8YKx6G+1ajIeEFL2UQR+3LzQsiJhQ2bl rf/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=OtfQx4B0WLYP5dmQVlOMcfd8LBC7vW+UVsItGtOvBCA=; b=ix5jDrJBSvnqqDz0U8rs7eBFRIddCPo4jukNj23dXnLuZw4UhlC1VWYGm8teQyHc8x HU9qEegKNUs3XVCaqrRYwAh1ou91SL3VT3hwNQZ7hMXSMyJma3dya+PFAtblpmrBxLdS QPQXvz/3UI/+MmkUJOt33f8ze46Hlo9hQwuC77K8IYSPp5pgv652Y/QvOU5z6YeMQ+Em 18QaFlW4+RIX+vsC5iXTs93FJRNYmBPBPzdzOwgB7+fvX6cTGSKAKql87Hc+fjRd144s sTe+PPA0AYwVAFPTBP5lh+MEq+4tDbsFdV8RVNILc1aNueIv0B8B6gOFl3CzoQyNKGet yuQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bbolFJSs; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l23-20020a637017000000b004607f6b2586si13247773pgc.736.2022.10.17.13.03.48; Mon, 17 Oct 2022 13:04:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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=@gmail.com header.s=20210112 header.b=bbolFJSs; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231159AbiJQUBt (ORCPT + 99 others); Mon, 17 Oct 2022 16:01:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231246AbiJQUB3 (ORCPT ); Mon, 17 Oct 2022 16:01:29 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EEAA38B; Mon, 17 Oct 2022 13:01:23 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id i17so14343613lja.3; Mon, 17 Oct 2022 13:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OtfQx4B0WLYP5dmQVlOMcfd8LBC7vW+UVsItGtOvBCA=; b=bbolFJSshQHmSaJsnuQPr/nEKD0L8/upvlaXfWgUE10V6j/txqguUvQdLn+/8xv7hB F/A3y/rlDLDtkREa9ZfKMOWbdR+/OysfAPuWfqoAtE1V3rHMyDVg4PcgGoPGQmx25c9+ GkCDQ0trvbyZz1HInGwtaNh4mmsnk3dVPWvxBDNjXD7pl15bG36lZ+gkUCQAyS4Cm9Xe EGITBPQUVzbPTpetvacMzkIeq4OyQCxc5EkoyvK52yfn0UTEYcvzwXg8RwpASI8f9Jf3 xxfxinH0PSZVNprYXr6dj7DYuq7wWX1YhPWi0MHv7LTcUA1YSnkKwaMOT9Plj7QTzaCu r5Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OtfQx4B0WLYP5dmQVlOMcfd8LBC7vW+UVsItGtOvBCA=; b=h625kLKL58bVqGMhT72NMVbuJFYU2qvoov/jwc4ehpqb4UbPEUBa6ALJkjdkEnUJUz opsU35ehXPES8nFy6aalQ8tlxrLAgbws1xtUxwBg92ww5Wp167mklxD2yVoYDfqDNYWQ Jb2tW8RvBafVYsv0JIDX22JjrwaENhA80+oO3rUf/rBOW7Z9YAXPSG0p/WSFUvDCCrRv UO1SBoFkuaRdz0t8v50S3kDGfOwMFSIQfxeFZfCTaPBryBePc/gwDTguGjHYS4CbGJvY R5yWvbES7mGN+KlEAb0kVYW8IA8LTYwJClC1edRNSrzD5CkOQrKDpjvcGReFOGTYZ7OB iV0w== X-Gm-Message-State: ACrzQf3v8sOiI/TMFvkqbDYr7qO56CYF+BxvcfOhNXiRdkjPOKur7Z8T 4zsAlX2IIS6y6bW+NrUPb7ieG/ALO8aI/rtAzsc= X-Received: by 2002:a05:651c:1310:b0:26f:c102:b73b with SMTP id u16-20020a05651c131000b0026fc102b73bmr4699400lja.432.1666036881999; Mon, 17 Oct 2022 13:01:21 -0700 (PDT) MIME-Version: 1.0 References: <20221017074432.12177-1-yin31149@gmail.com> In-Reply-To: <20221017074432.12177-1-yin31149@gmail.com> From: Luiz Augusto von Dentz Date: Mon, 17 Oct 2022 13:01:10 -0700 Message-ID: Subject: Re: [PATCH] Bluetooth: L2CAP: Fix memory leak in vhci_write To: Hawkins Jiawei Cc: syzbot+8f819e36e01022991cfa@syzkaller.appspotmail.com, Marcel Holtmann , Johan Hedberg , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, 18801353760@163.com, Luiz Augusto von Dentz , netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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-bluetooth@vger.kernel.org Hi Hawkins, On Mon, Oct 17, 2022 at 12:47 AM Hawkins Jiawei wrote: > > Syzkaller reports a memory leak as follows: > ==================================== > BUG: memory leak > unreferenced object 0xffff88810d81ac00 (size 240): > [...] > hex dump (first 32 bytes): > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > backtrace: > [] __alloc_skb+0x1f9/0x270 net/core/skbuff.c:418 > [] alloc_skb include/linux/skbuff.h:1257 [inline] > [] bt_skb_alloc include/net/bluetooth/bluetooth.h:469 [inline] > [] vhci_get_user drivers/bluetooth/hci_vhci.c:391 [inline] > [] vhci_write+0x5f/0x230 drivers/bluetooth/hci_vhci.c:511 > [] call_write_iter include/linux/fs.h:2192 [inline] > [] new_sync_write fs/read_write.c:491 [inline] > [] vfs_write+0x42d/0x540 fs/read_write.c:578 > [] ksys_write+0x9d/0x160 fs/read_write.c:631 > [] do_syscall_x64 arch/x86/entry/common.c:50 [inline] > [] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 > [] entry_SYSCALL_64_after_hwframe+0x63/0xcd > ==================================== > > HCI core will uses hci_rx_work() to process frame, which is queued to > the hdev->rx_q tail in hci_recv_frame() by HCI driver. > > Yet the problem is that, HCI core does not free the skb after handling > ACL data packets. To be more specific, when start fragment does not > contain the L2CAP length, HCI core just reads possible bytes and > finishes frame process in l2cap_recv_acldata(), without freeing the skb, > which triggers the above memory leak. > > This patch solves it by releasing the relative skb, after processing the > above case in l2cap_recv_acldata() > > Fixes: 4d7ea8ee90e4 ("Bluetooth: L2CAP: Fix handling fragmented length") > Link: https://lore.kernel.org/all/0000000000000d0b1905e6aaef64@google.com/ > Reported-and-tested-by: syzbot+8f819e36e01022991cfa@syzkaller.appspotmail.com > Signed-off-by: Hawkins Jiawei > --- > net/bluetooth/l2cap_core.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c > index 1f34b82ca0ec..e0a00854c02e 100644 > --- a/net/bluetooth/l2cap_core.c > +++ b/net/bluetooth/l2cap_core.c > @@ -8426,9 +8426,8 @@ void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags) > * expected length. > */ > if (skb->len < L2CAP_LEN_SIZE) { > - if (l2cap_recv_frag(conn, skb, conn->mtu) < 0) > - goto drop; > - return; > + l2cap_recv_frag(conn, skb, conn->mtu); > + goto drop; Let us use break; instead of goto drop since we have copied the skb into rx_sbk. > } > > len = get_unaligned_le16(skb->data) + L2CAP_HDR_SIZE; > @@ -8472,7 +8471,7 @@ void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags) > > /* Header still could not be read just continue */ > if (conn->rx_skb->len < L2CAP_LEN_SIZE) > - return; > + goto drop; > } > > if (skb->len > conn->rx_len) { > -- > 2.25.1 > -- Luiz Augusto von Dentz