Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp183664iol; Thu, 9 Jun 2022 01:28:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybFs453QjULP/vG2Car809DPxNpylNXdA6L/0cScswdcyVMBA7c5nKM6/EQt1yEFqNYof/ X-Received: by 2002:a17:907:1b14:b0:6ef:a5c8:afbd with SMTP id mp20-20020a1709071b1400b006efa5c8afbdmr35049289ejc.151.1654763283639; Thu, 09 Jun 2022 01:28:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654763283; cv=none; d=google.com; s=arc-20160816; b=yNIL5PODLMQtrpBwpY8DphH4kV9hgtetAeLFhJJoFkQVQj9v/lp4k8QQdlWTrK9C/o 2j0jLms0hbJjwI/MJJNFIBqfPH7P1zOcQd2wB2skAvM/LnpZsebauytIIUCzpus0n9sG 4whpogrjePHyj7aARZOJd+o0CyQW/3QOln8vw5rFRZiKjccZRdNPwqy3uu+xOmR5reXD 8zQ2mgimmBTKML2P1H0dNBVdEsj4taXvVD5Q7mUeA2WYIXOKw1HPGckivl7gzbyP8j0/ xAjpgYn1R9guixC238tBj6mrENpjg//CnsW6AdqN6lUQyd/9zIY2NUB3chayIWytZlrp cxpA== 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=AXjTL338GE8J9mXU1xy88Qy/439/Cg4obvbWdAG4qFI=; b=HS3RepTvxAay9FeHgkrNxqEejtl33U0iBfZEsboFG0oSENg2q72U+d1mVcq44LUuvW Mumwz2r26DH+DUn1yUKMHkFNbP7eDrumpz7aiDqQGF2peqenfgHPq/qeb4ePdQswmy40 xLnUj3vpo3UVhoHZyv13N/g5SZpBCgszqCcJB/CySzM3nEPmpuGJcZ+WMwnbdqPJ7rUO TGyRhd904tQqC2Tn8vREF0E8oJfsqQsGptF8Lc/yAbstOtRKFOJt3eeySNRSlbVZp+fg SMoHMVS6tuuNUbJZWU8Uone5EIod0cjPeOvTM4Tts+xQUBlAeB4vYli8PHJJnl9aXo3n fmUg== 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 dd5-20020a1709069b8500b00708f2732f66si23696699ejc.122.2022.06.09.01.27.37; Thu, 09 Jun 2022 01:28:03 -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 S232730AbiFIIU6 (ORCPT + 99 others); Thu, 9 Jun 2022 04:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231641AbiFIIU4 (ORCPT ); Thu, 9 Jun 2022 04:20:56 -0400 Received: from giacobini.uberspace.de (giacobini.uberspace.de [185.26.156.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAB4D3B9269 for ; Thu, 9 Jun 2022 01:20:50 -0700 (PDT) Received: (qmail 26772 invoked by uid 990); 9 Jun 2022 08:20:48 -0000 Authentication-Results: giacobini.uberspace.de; auth=pass (plain) Message-ID: Date: Thu, 9 Jun 2022 10:20:47 +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] 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: <20220608135105.146452-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(-1.07202) SUSPICIOUS_RECIPS(1.5) X-Rspamd-Score: 0.327979 Received: from unknown (HELO unkown) (::1) by giacobini.uberspace.de (Haraka/2.8.28) with ESMTPSA; Thu, 09 Jun 2022 10:20:48 +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 08.06.22 17:33, Eric Dumazet wrote: > On Wed, Jun 8, 2022 at 6:51 AM Soenke Huster wrote: >> >> Use the skb helper instead of direct manipulation. This fixes the >> following page fault, when connecting my Android phone: >> >> 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) >> >> Signed-off-by: Soenke Huster >> --- >> net/bluetooth/rfcomm/core.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c >> index 7324764384b6..7360e905d045 100644 >> --- a/net/bluetooth/rfcomm/core.c >> +++ b/net/bluetooth/rfcomm/core.c >> @@ -1747,8 +1747,8 @@ static struct rfcomm_session *rfcomm_recv_frame(struct rfcomm_session *s, >> type = __get_type(hdr->ctrl); >> >> /* Trim FCS */ >> - skb->len--; skb->tail--; >> - fcs = *(u8 *)skb_tail_pointer(skb); >> + skb_trim(skb, skb->len - 1); >> + fcs = *(skb->data + skb->len); >> > > Hmmm... I do not see any difference before/after in term of memory > dereference to get fcs. > > I think you should give more details on how exactly the bug triggers. Sorry, yesterday I was not able to track down why exactly it crashes, but by now I think I figured it out. The crash happens when using Bluetooth in a virtual machine. On connecting my Android phone to the physical controller which I use inside the virtual machine via the VirtIO driver, after some seconds the crash occurs. Before the trimming step, I examined the skb in gdb and saw, that skb->tail is zero. Thus, skb->tail--; modifies the unsigned integer to -1 resp. MAX_UINT. In skb_tail_pointer, skb->head + skb->tail is calculated which results in the page fault. By using skb_trim, skb->tail is set to the accurate value and thus the issue is fixed. I am not an expert in the Linux kernel area, do you think there is an underlying issue anywhere else? When using my Android phone on my host computer, I do not have that problem - it might be in some (e.g. virtio_bt?) driver? On the other hand, with the patch my problem is solved and the phone is usable in the virtual machine!