From patchwork Tue Feb 8 22:19:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Menzel X-Patchwork-Id: 540848 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E28CC433FE for ; Tue, 8 Feb 2022 22:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387156AbiBHWVt (ORCPT ); Tue, 8 Feb 2022 17:21:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345032AbiBHWUw (ORCPT ); Tue, 8 Feb 2022 17:20:52 -0500 Received: from mx1.molgen.mpg.de (mx3.molgen.mpg.de [141.14.17.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F734C0612B8; Tue, 8 Feb 2022 14:20:50 -0800 (PST) Received: from localhost.localdomain (ip5f5aebc2.dynamic.kabel-deutschland.de [95.90.235.194]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pmenzel) by mx.molgen.mpg.de (Postfix) with ESMTPSA id 16BEA61E64846; Tue, 8 Feb 2022 23:20:47 +0100 (CET) From: Paul Menzel To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Jakub Kicinski Cc: Paul Menzel , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] Revert "Bluetooth: Fix passing NULL to PTR_ERR" Date: Tue, 8 Feb 2022 23:19:10 +0100 Message-Id: <20220208221911.57058-1-pmenzel@molgen.mpg.de> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This reverts commit 266191aa8d14b84958aaeb5e96ee4e97839e3d87, so that commit 81be03e026dc ("Bluetooth: RFCOMM: Replace use of memcpy_from_msg with bt_skb_sendmmsg"), introducing a regression, can be reverted. Signed-off-by: Paul Menzel --- include/net/bluetooth/bluetooth.h | 2 +- net/bluetooth/rfcomm/sock.c | 2 +- net/bluetooth/sco.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 4b3d0b16c185..318df161e6d3 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -505,7 +505,7 @@ static inline struct sk_buff *bt_skb_sendmmsg(struct sock *sk, struct sk_buff *tmp; tmp = bt_skb_sendmsg(sk, msg, len, mtu, headroom, tailroom); - if (IS_ERR(tmp)) { + if (IS_ERR_OR_NULL(tmp)) { kfree_skb(skb); return tmp; } diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index 4bf4ea6cbb5e..5938af3e9936 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -583,7 +583,7 @@ static int rfcomm_sock_sendmsg(struct socket *sock, struct msghdr *msg, skb = bt_skb_sendmmsg(sk, msg, len, d->mtu, RFCOMM_SKB_HEAD_RESERVE, RFCOMM_SKB_TAIL_RESERVE); - if (IS_ERR(skb)) + if (IS_ERR_OR_NULL(skb)) return PTR_ERR(skb); sent = rfcomm_dlc_send(d, skb); diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index 8eabf41b2993..7ebc9d294f0c 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -734,7 +734,7 @@ static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg, return -EOPNOTSUPP; skb = bt_skb_sendmsg(sk, msg, len, len, 0, 0); - if (IS_ERR(skb)) + if (IS_ERR_OR_NULL(skb)) return PTR_ERR(skb); lock_sock(sk); From patchwork Tue Feb 8 22:19:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Menzel X-Patchwork-Id: 540847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0535BC433EF for ; Tue, 8 Feb 2022 22:21:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387230AbiBHWVx (ORCPT ); Tue, 8 Feb 2022 17:21:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387272AbiBHWU4 (ORCPT ); Tue, 8 Feb 2022 17:20:56 -0500 Received: from mx1.molgen.mpg.de (mx3.molgen.mpg.de [141.14.17.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAEC3C0612B8; Tue, 8 Feb 2022 14:20:55 -0800 (PST) Received: from localhost.localdomain (ip5f5aebc2.dynamic.kabel-deutschland.de [95.90.235.194]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pmenzel) by mx.molgen.mpg.de (Postfix) with ESMTPSA id 4669B61E64846; Tue, 8 Feb 2022 23:20:54 +0100 (CET) From: Paul Menzel To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Jakub Kicinski Cc: Paul Menzel , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] Revert "Bluetooth: RFCOMM: Replace use of memcpy_from_msg with bt_skb_sendmmsg" Date: Tue, 8 Feb 2022 23:19:11 +0100 Message-Id: <20220208221911.57058-2-pmenzel@molgen.mpg.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208221911.57058-1-pmenzel@molgen.mpg.de> References: <20220208221911.57058-1-pmenzel@molgen.mpg.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This reverts commit 81be03e026dc0c16dc1c64e088b2a53b73caa895. Since the commit, transferring files greater than some bytes to the Nokia N9 (MeeGo) or Jolla (Sailfish OS) is not possible anymore. # obexctl [NEW] Client /org/bluez/obex [obex]# connect 40:98:4E:5B:CE:XX Attempting to connect to 40:98:4E:5B:CE:XX [NEW] Session /org/bluez/obex/client/session0 [default] [NEW] ObjectPush /org/bluez/obex/client/session0 Connection successful [40:98:4E:5B:CE:XX]# send /lib/systemd/systemd Attempting to send /lib/systemd/systemd to /org/bluez/obex/client/session0 [NEW] Transfer /org/bluez/obex/client/session0/transfer0 Transfer /org/bluez/obex/client/session0/transfer0 Status: queued Name: systemd Size: 1841712 Filename: /lib/systemd/systemd Session: /org/bluez/obex/client/session0 [CHG] Transfer /org/bluez/obex/client/session0/transfer0 Status: active [CHG] Transfer /org/bluez/obex/client/session0/transfer0 Transferred: 32737 (@32KB/s 00:55) [CHG] Transfer /org/bluez/obex/client/session0/transfer0 Status: error [DEL] Transfer /org/bluez/obex/client/session0/transfer0 Reverting it, fixes the regression. Link: https://lore.kernel.org/linux-bluetooth/aa3ee7ac-6c52-3861-1798-3cc1a37f6ebf@molgen.mpg.de/T/#m1f9673e4ab0d55a7dccf87905337ab2e67d689f1 Signed-off-by: Paul Menzel --- net/bluetooth/rfcomm/core.c | 50 ++++++------------------------------- net/bluetooth/rfcomm/sock.c | 46 ++++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 53 deletions(-) diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c index 7324764384b6..f2bacb464ccf 100644 --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c @@ -549,58 +549,22 @@ struct rfcomm_dlc *rfcomm_dlc_exists(bdaddr_t *src, bdaddr_t *dst, u8 channel) return dlc; } -static int rfcomm_dlc_send_frag(struct rfcomm_dlc *d, struct sk_buff *frag) -{ - int len = frag->len; - - BT_DBG("dlc %p mtu %d len %d", d, d->mtu, len); - - if (len > d->mtu) - return -EINVAL; - - rfcomm_make_uih(frag, d->addr); - __skb_queue_tail(&d->tx_queue, frag); - - return len; -} - int rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb) { - unsigned long flags; - struct sk_buff *frag, *next; - int len; + int len = skb->len; if (d->state != BT_CONNECTED) return -ENOTCONN; - frag = skb_shinfo(skb)->frag_list; - skb_shinfo(skb)->frag_list = NULL; - - /* Queue all fragments atomically. */ - spin_lock_irqsave(&d->tx_queue.lock, flags); - - len = rfcomm_dlc_send_frag(d, skb); - if (len < 0 || !frag) - goto unlock; - - for (; frag; frag = next) { - int ret; - - next = frag->next; - - ret = rfcomm_dlc_send_frag(d, frag); - if (ret < 0) { - kfree_skb(frag); - goto unlock; - } + BT_DBG("dlc %p mtu %d len %d", d, d->mtu, len); - len += ret; - } + if (len > d->mtu) + return -EINVAL; -unlock: - spin_unlock_irqrestore(&d->tx_queue.lock, flags); + rfcomm_make_uih(skb, d->addr); + skb_queue_tail(&d->tx_queue, skb); - if (len > 0 && !test_bit(RFCOMM_TX_THROTTLED, &d->flags)) + if (!test_bit(RFCOMM_TX_THROTTLED, &d->flags)) rfcomm_schedule(); return len; } diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index 5938af3e9936..2c95bb58f901 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -575,20 +575,46 @@ static int rfcomm_sock_sendmsg(struct socket *sock, struct msghdr *msg, lock_sock(sk); sent = bt_sock_wait_ready(sk, msg->msg_flags); + if (sent) + goto done; - release_sock(sk); + while (len) { + size_t size = min_t(size_t, len, d->mtu); + int err; - if (sent) - return sent; + skb = sock_alloc_send_skb(sk, size + RFCOMM_SKB_RESERVE, + msg->msg_flags & MSG_DONTWAIT, &err); + if (!skb) { + if (sent == 0) + sent = err; + break; + } + skb_reserve(skb, RFCOMM_SKB_HEAD_RESERVE); + + err = memcpy_from_msg(skb_put(skb, size), msg, size); + if (err) { + kfree_skb(skb); + if (sent == 0) + sent = err; + break; + } + + skb->priority = sk->sk_priority; + + err = rfcomm_dlc_send(d, skb); + if (err < 0) { + kfree_skb(skb); + if (sent == 0) + sent = err; + break; + } - skb = bt_skb_sendmmsg(sk, msg, len, d->mtu, RFCOMM_SKB_HEAD_RESERVE, - RFCOMM_SKB_TAIL_RESERVE); - if (IS_ERR_OR_NULL(skb)) - return PTR_ERR(skb); + sent += size; + len -= size; + } - sent = rfcomm_dlc_send(d, skb); - if (sent < 0) - kfree_skb(skb); +done: + release_sock(sk); return sent; }