Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1499422iol; Fri, 10 Jun 2022 08:42:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwrFp2RR2ndEd+F9HtzoQQg5qGvlNZ5VxPF1yyBHBnZv7NpRxgW4ZzlkHYKYGSXaMaGKDc X-Received: by 2002:a17:907:160f:b0:70f:cceb:d78c with SMTP id hb15-20020a170907160f00b0070fccebd78cmr33422272ejc.247.1654875743307; Fri, 10 Jun 2022 08:42:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654875743; cv=none; d=google.com; s=arc-20160816; b=n5HsSajvS1QKCdLp5HFffkdHZFFxmF6yyp04lBSwDKWap8SfvegEn9YFWIOnvUdpSs CYAdN1siLFsS2WvrmKLoWvEy/YoP22+KhzSnEo2aDnUPdgQ5z/dnxM9PA54ce86l6e26 3JYQErjqRt79Z7hZvAX/xDnneOGyA4Jj/03cgsalW0p14/IpAtMaJ29If4wBN7fiFkI2 ZOpxVlLMKBS2TItcAg+b1q6pafvnRQoFARq4qqcWAFKBwqwEWMGZEHL8Bac7ACaASx4C tckDQSyEl5TWtb0hc+l3mrVsllonLZnri7bt58UCosLjZWS7b+jXgNKBUe7F7oETroSh Mv6w== 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; bh=30TpR1mXJ+N77lfX0lHWyg2lRCl9x7rNWj7PxPmmoK0=; b=Jsvj/Pz/xCBuh+ZgVErkngfZSrxOmYc56fSCFk0DL0p+ugrjq/8/mwL+iurNr7Yuq5 5vjH0zUbTRw62MGVfzdag5cpbjI7nxCWTegaFG1+Ru30cb8dJvQqjxpqci/eJV80soQA Lemyy/SycvYahCbwTEvMc4AOXWw8MEKnu49DjS3uvNzDIxE1D+BvL/sIWar093toMfTf rxqJoc1qDETddc/dtMHUijocx3XkqS/zm9IrdkMGbL4HdZy1W0CgqaERvUF7KG1Cy+0r pMe/HoVkT1x/knCW3LCAVtOU+yzu6EUqyV1ufkkTpfERPLaz8T/JCDhEZMRTNHKhJ/pf Anqg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020a056402358c00b0042b2ced426csi6723971edc.521.2022.06.10.08.41.55; Fri, 10 Jun 2022 08:42:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344979AbiFJPfm (ORCPT + 99 others); Fri, 10 Jun 2022 11:35:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242953AbiFJPfm (ORCPT ); Fri, 10 Jun 2022 11:35:42 -0400 Received: from giacobini.uberspace.de (giacobini.uberspace.de [185.26.156.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29909228484 for ; Fri, 10 Jun 2022 08:35:38 -0700 (PDT) Received: (qmail 21352 invoked by uid 990); 10 Jun 2022 15:35:37 -0000 Authentication-Results: giacobini.uberspace.de; auth=pass (plain) Message-ID: <9f214837-dc68-ef1a-0199-27d6af582115@eknoes.de> Date: Fri, 10 Jun 2022 17:35:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH v2] Bluetooth: RFCOMM: Use skb_trim to trim checksum Content-Language: en-US To: Eric Dumazet Cc: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Jakub Kicinski , Paolo Abeni , linux-bluetooth@vger.kernel.org, netdev , LKML References: <20220610110749.110881-1-soenke.huster@eknoes.de> From: =?UTF-8?Q?S=c3=b6nke_Huster?= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Bar: - X-Rspamd-Report: MIME_GOOD(-0.1) BAYES_HAM(-2.998944) SUSPICIOUS_RECIPS(1.5) X-Rspamd-Score: -1.598944 Received: from unknown (HELO unkown) (::1) by giacobini.uberspace.de (Haraka/2.8.28) with ESMTPSA; Fri, 10 Jun 2022 17:35:37 +0200 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, MSGID_FROM_MTA_HEADER,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Eric, On 10.06.22 15:59, Eric Dumazet wrote: > On Fri, Jun 10, 2022 at 4:08 AM Soenke Huster wrote: >> >> As skb->tail might be zero, it can underflow. This leads to a page >> fault: skb_tail_pointer simply adds skb->tail (which is now MAX_UINT) >> to skb->head. >> >> BUG: unable to handle page fault for address: ffffed1021de29ff >> #PF: supervisor read access in kernel mode >> #PF: error_code(0x0000) - not-present page >> RIP: 0010:rfcomm_run+0x831/0x4040 (net/bluetooth/rfcomm/core.c:1751) >> >> By using skb_trim instead of the direct manipulation, skb->tail >> is reset. Thus, the correct pointer to the checksum is used. >> >> Signed-off-by: Soenke Huster >> --- >> v2: Clarified how the bug triggers, minimize code change >> >> net/bluetooth/rfcomm/core.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c >> index 7324764384b6..443b55edb3ab 100644 >> --- a/net/bluetooth/rfcomm/core.c >> +++ b/net/bluetooth/rfcomm/core.c >> @@ -1747,7 +1747,7 @@ static struct rfcomm_session *rfcomm_recv_frame(struct rfcomm_session *s, >> type = __get_type(hdr->ctrl); >> >> /* Trim FCS */ >> - skb->len--; skb->tail--; >> + skb_trim(skb, skb->len - 1); >> fcs = *(u8 *)skb_tail_pointer(skb); >> >> if (__check_fcs(skb->data, type, fcs)) { >> -- >> 2.36.1 >> > > Again, I do not see how skb->tail could possibly zero at this point. > > If it was, skb with illegal layout has been queued in the first place, > we need to fix the producer, not the consumer. > Sorry, I thought that might be a right place as there is not much code in the kernel that manipulates ->tail directly. > A driver missed an skb_put() perhaps. > I am using the (I guess quite unused) virtio_bt driver, and figured out that the following fixes the bug: --- a/drivers/bluetooth/virtio_bt.c +++ b/drivers/bluetooth/virtio_bt.c @@ -219,7 +219,7 @@ static void virtbt_rx_work(struct work_struct *work) if (!skb) return; - skb->len = len; + skb_put(skb, len); virtbt_rx_handle(vbt, skb); if (virtbt_add_inbuf(vbt) < 0) I guess this is the root cause? I just used Bluetooth for a while in the VM and no error occurred, everything worked fine. > Can you please dump the skb here ? > > diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c > index 7324764384b6773074032ad671777bf86bd3360e..358ccb4fe7214aea0bb4084188c7658316fe0ff7 > 100644 > --- a/net/bluetooth/rfcomm/core.c > +++ b/net/bluetooth/rfcomm/core.c > @@ -1746,6 +1746,11 @@ static struct rfcomm_session > *rfcomm_recv_frame(struct rfcomm_session *s, > dlci = __get_dlci(hdr->addr); > type = __get_type(hdr->ctrl); > > + if (!skb->tail) { > + DO_ONCE_LITE(skb_dump(KERN_ERR, skb, false)); > + kfree_skb(skb); > + return s; > + } > /* Trim FCS */ > skb->len--; skb->tail--; > fcs = *(u8 *)skb_tail_pointer(skb); If it might still help: skb len=4 headroom=9 headlen=4 tailroom=1728 mac=(-1,-1) net=(0,-1) trans=-1 shinfo(txflags=0 nr_frags=0 gso(size=0 type=0 segs=0)) csum(0x0 ip_summed=0 complete_sw=0 valid=0 level=0) hash(0x0 sw=0 l4=0) proto=0x0000 pkttype=0 iif=0 skb linear: 00000000: 03 3f 01 1c