Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1930029rwb; Fri, 19 Aug 2022 11:54:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR7w89gXJ5auSLEK0H/MapTJ2PWTPkM8UfVfFokqdE93PCyPcnDXbOKKG9/nRm3rzd1o0K68 X-Received: by 2002:a17:907:3f85:b0:733:3f0e:2f28 with SMTP id hr5-20020a1709073f8500b007333f0e2f28mr5600098ejc.376.1660935277646; Fri, 19 Aug 2022 11:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660935277; cv=none; d=google.com; s=arc-20160816; b=VsKzzE6FOS4Z+WmvDeKSsoW6Rri/ojUBupWHzmG9q7UpFUNydHG5hf4JgRhUfbZaSx wNyHEq7zS4nYh0Bhd4SuCAltb5VIn2+X543EPpLfCLmd2JI/63c9hYSz4ZZuUf2kzIRY RgZTlxwfThDX87b1hD5F7CNAKtx9HbE2/ggVlEOBVAHpTtSgdS9GvNy43m241+x1kCS4 7Xc3+RHNlaISmae1LV0bK+JSepdbvIFZJVvxnqhU0fUMXMLpy3dKA981vlfcewglahU+ IK6ZK7aED2w9+OeVB3p8HuIi7UeaN2nFGpaawPpyt/M6gyiFY91K8ncI2cZONiJlGKvV zOUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=RY0MEx0c3zHjGr9mFTA3DzqjpOmb+3Xm6UWnhkXTaxY=; b=rYSq6dsrYbyXfg99/t90w1QTShcQGMs1if727kyPx+5p2XRc0IkYL2gkAy12u/2LyN hh2oHdvJbAlT4QGJ+Zt1N7iPkO6bd42Cm833DISNApx/iuFi9k534XCmOzRbeSWBEHR5 ml3kQyicf81aQa8HiSdxJlM/KvNusF9O9/v2lmzMrTJLgCCYt+WlQXlhatSWY/TSTX36 91TX9Z0Zi/JMBlZ3B2IIFTHK1TL+YqDEHTFwhmyKb6Tav3vQAzXGqdBTq71QrIuLtJuD jD32Mrg9r/ygkE3+nKOGHKSs429+sPbQy+hPoTm9rBv2/kkbrkVRys1UmYRcsEMyHGO4 3xtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iSOrJet5; 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 l19-20020a170906795300b0073309f33443si3678957ejo.636.2022.08.19.11.54.12; Fri, 19 Aug 2022 11:54:37 -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=iSOrJet5; 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 S1350851AbiHSSqh (ORCPT + 99 others); Fri, 19 Aug 2022 14:46:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350231AbiHSSqh (ORCPT ); Fri, 19 Aug 2022 14:46:37 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DC7C5A808 for ; Fri, 19 Aug 2022 11:46:36 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id d71so4325597pgc.13 for ; Fri, 19 Aug 2022 11:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc; bh=RY0MEx0c3zHjGr9mFTA3DzqjpOmb+3Xm6UWnhkXTaxY=; b=iSOrJet5aHNnQ8RRXC+zU0XbkQcmpzM/5p0oEEWtkoX+kB6PubZuflo79C+EoSqJYk 6NAY7jCcYVsHLfEpHuS22+X3ZUFhiH7ohS+rWm85mFtn6MdatHNzoYDfXbQ+Quad8yEj yThJz98nPs3lflKdvQkosCTZ13NDMNpEoID++v/l5SnCVy/r12Mx00kKg/g/IXGLabVO cwzOHt/LsWSbwYAsnzQXPvN8QHrFrX3rQzC3sqi6AvK6Bj+gidR5VLbmHR4E0kCIPUsv mQTt+cGq7ZfkUzvR2BMOhDyPSFYykxUa2Lt8RRDBWtr/knJvNZjmh4OkhSz+uL5pOw6x xa4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc; bh=RY0MEx0c3zHjGr9mFTA3DzqjpOmb+3Xm6UWnhkXTaxY=; b=oyUyDvCtP86BX05N8UO7rk6PyAi3Q8zf2HMAMBCyPG7t/ZFYAN293zSO7afnXroJ2H eFLy7SYxynIYWjUTSZnLEUHyA499pXjm4Jye2nC4wNBBL+KuDhuI9g21rfmWW0/GSUkN 8cRdqkKgCL6zyFiYk92b5h7Z7L3USg01dfwEq+m2ZZdFFWpXthqRdu8rQYvxIMs0ZEGP LyDDIKlfTmbwligyyJxShd5MD5/wLVvLMBviQmmGYv+kraEBQQ+UjQJaiug8FujqiU5L VEX7UyFDd/+HtCHb/AZCdeWV6P1LyWW/QgPJWjWtpcIMllavDOrI+rwrgI4hOhh9X0MK kDIQ== X-Gm-Message-State: ACgBeo0LxCa3hxGh0Z0O9PeLCNAlm59GQhlzKJj7QqZadDcuDgc1neUC ddrcSu2SS2278eRvVa3DyI2JU+Qb2Cc= X-Received: by 2002:a05:6a00:188a:b0:536:1401:7f65 with SMTP id x10-20020a056a00188a00b0053614017f65mr3775371pfh.1.1660934795161; Fri, 19 Aug 2022 11:46:35 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id t28-20020a62d15c000000b0052d82ce65a9sm3869649pfl.143.2022.08.19.11.46.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 11:46:34 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH] Bluetooth: ISO: Fix not handling shutdown condition Date: Fri, 19 Aug 2022 11:46:33 -0700 Message-Id: <20220819184633.19437-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE 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 From: Luiz Augusto von Dentz In order to properly handle shutdown syscall the code shall not assume that the how argument is always SHUT_RDWR resulting in SHUTDOWN_MASK as that would result in poll to immediatelly report EPOLLHUP instead of properly waiting for disconnect_cfm (Disconnect Complete) which is rather important for the likes of BAP as the CIG may need to be reprogrammed. Fixes: ccf74f2390d6 ("Bluetooth: Add BTPROTO_ISO socket type") Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/iso.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c index ced8ad4fed4f..b50a69064fee 100644 --- a/net/bluetooth/iso.c +++ b/net/bluetooth/iso.c @@ -1317,17 +1317,32 @@ static int iso_sock_shutdown(struct socket *sock, int how) sock_hold(sk); lock_sock(sk); - if (!sk->sk_shutdown) { - sk->sk_shutdown = SHUTDOWN_MASK; - iso_sock_clear_timer(sk); - __iso_sock_close(sk); - - if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime && - !(current->flags & PF_EXITING)) - err = bt_sock_wait_state(sk, BT_CLOSED, - sk->sk_lingertime); + switch (how) { + case SHUT_RD: + if (sk->sk_shutdown & RCV_SHUTDOWN) + goto unlock; + sk->sk_shutdown |= RCV_SHUTDOWN; + break; + case SHUT_WR: + if (sk->sk_shutdown & SEND_SHUTDOWN) + goto unlock; + sk->sk_shutdown |= SEND_SHUTDOWN; + break; + case SHUT_RDWR: + if (sk->sk_shutdown & SHUTDOWN_MASK) + goto unlock; + sk->sk_shutdown |= SHUTDOWN_MASK; + break; } + iso_sock_clear_timer(sk); + __iso_sock_close(sk); + + if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime && + !(current->flags & PF_EXITING)) + err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime); + +unlock: release_sock(sk); sock_put(sk); -- 2.37.2