From patchwork Sat Jan 15 12:26:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12714374 X-Patchwork-Delegate: kuba@kernel.org 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 198A6C4332F for ; Sat, 15 Jan 2022 12:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231229AbiAOM1E (ORCPT ); Sat, 15 Jan 2022 07:27:04 -0500 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:47500 "EHLO smtp-relay-internal-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230471AbiAOM1C (ORCPT ); Sat, 15 Jan 2022 07:27:02 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 38CD74005A for ; Sat, 15 Jan 2022 12:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642249617; bh=zOPm6FbYYyMSwfxLvkRzL4Z981RZYudJxTNTqLX9Fek=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hPcW6J5XBELywkGxSm6BpY2FjxX2FxCs6xuz83qeyhrC/38SCvntdOz+aM5GvFtRP wWe4OVCefHaP56cH1XWoirkJzFAVRVJ2vFtfoB411JCwmw3O/7RS/SVTKHXg4II/6m zUH+6VvXKcwDtq1f3VXX6VcLN/Y2EXxslHon1ud1TSONpc6n71MiShi6XZmOJWxX+/ qDZdr5KGYv5pBhOxKC8YOYT1VLIO0lBBIamAL0gyiWYKpuCsWC2IpuH3OPxXg7PD81 51k42fH7niBLZX4o17qKxjJmawi/1EBZV8Dp1V56EQgkjaCUPe/cYT1PECnOTg/3x7 X334cp161DExw== Received: by mail-wm1-f71.google.com with SMTP id v190-20020a1cacc7000000b0034657bb6a66so3591257wme.6 for ; Sat, 15 Jan 2022 04:26:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zOPm6FbYYyMSwfxLvkRzL4Z981RZYudJxTNTqLX9Fek=; b=zluGN4cGdlbU/PUKoGbPvaSh7bGVTsnngj1xEmYO7+P//0PITHm/ZdJAfGXG2W7EoI A1ssAWs3nopVBrEmAzjGIPw7xB0LvVFDtmyVbULrLNUqY/owOEDZYcmjXKfSNftgvzMd Dp93lKfuNteV506cVDaZABBxSx4TiotcPJauNugz1eycUhiS+Y8HT1utoAeLwxGgEiLi FyNlg57oSdjqGbEDK6Gk+zmZVZd4K8q1AKt+pcfp7ou6gkRDzV2fXAptaxR3e2KmOnnW nqmQPW2C3BZJDkD0+/jbCdrOkM6x3dDbPgaYZjtZB6P09wFn1r+ptRdfKIPpawye3U2F sn0g== X-Gm-Message-State: AOAM5307tmn12eLDzbqpHKJBb/wqnE2VlWvsEd5l5wMB7KECxQaVvmvx N88ggkMOlfUF20w/XvMEqKXSoN6vAzZqO0jelloDxSKyb5u680MeZwqEaPPVUpSIafPFhzLGtJ5 eNXZGNtg95P/IkxEDwVTzjdBd8nCzVvvG+g== X-Received: by 2002:adf:ec04:: with SMTP id x4mr11680484wrn.688.1642249616334; Sat, 15 Jan 2022 04:26:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgIS3ERL+kQQ2s/1KY8gz3ov5974t4pocea/WSltWsoYThkoVVF5w/zE3maTb43pWLhNWOXQ== X-Received: by 2002:adf:ec04:: with SMTP id x4mr11680471wrn.688.1642249616161; Sat, 15 Jan 2022 04:26:56 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id bk17sm7878476wrb.105.2022.01.15.04.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jan 2022 04:26:55 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: syzbot+7f23bcddf626e0593a39@syzkaller.appspotmail.com, stable@vger.kernel.org Subject: [PATCH 1/7] nfc: llcp: fix NULL error pointer dereference on sendmsg() after failed bind() Date: Sat, 15 Jan 2022 13:26:44 +0100 Message-Id: <20220115122650.128182-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> References: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Syzbot detected a NULL pointer dereference of nfc_llcp_sock->dev pointer (which is a 'struct nfc_dev *') with calls to llcp_sock_sendmsg() after a failed llcp_sock_bind(). The message being sent is a SOCK_DGRAM. KASAN report: BUG: KASAN: null-ptr-deref in nfc_alloc_send_skb+0x2d/0xc0 Read of size 4 at addr 00000000000005c8 by task llcp_sock_nfc_a/899 CPU: 5 PID: 899 Comm: llcp_sock_nfc_a Not tainted 5.16.0-rc6-next-20211224-00001-gc6437fbf18b0 #125 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 Call Trace: dump_stack_lvl+0x45/0x59 ? nfc_alloc_send_skb+0x2d/0xc0 __kasan_report.cold+0x117/0x11c ? mark_lock+0x480/0x4f0 ? nfc_alloc_send_skb+0x2d/0xc0 kasan_report+0x38/0x50 nfc_alloc_send_skb+0x2d/0xc0 nfc_llcp_send_ui_frame+0x18c/0x2a0 ? nfc_llcp_send_i_frame+0x230/0x230 ? __local_bh_enable_ip+0x86/0xe0 ? llcp_sock_connect+0x470/0x470 ? llcp_sock_connect+0x470/0x470 sock_sendmsg+0x8e/0xa0 ____sys_sendmsg+0x253/0x3f0 ... The issue was visible only with multiple simultaneous calls to bind() and sendmsg(), which resulted in most of the bind() calls to fail. The bind() was failing on checking if there is available WKS/SDP/SAP (respective bit in 'struct nfc_llcp_local' fields). When there was no available WKS/SDP/SAP, the bind returned error but the sendmsg() to such socket was able to trigger mentioned NULL pointer dereference of nfc_llcp_sock->dev. The code looks simply racy and currently it protects several paths against race with checks for (!nfc_llcp_sock->local) which is NULL-ified in error paths of bind(). The llcp_sock_sendmsg() did not have such check but called function nfc_llcp_send_ui_frame() had, although not protected with lock_sock(). Therefore the race could look like (same socket is used all the time): CPU0 CPU1 ==== ==== llcp_sock_bind() - lock_sock() - success - release_sock() - return 0 llcp_sock_sendmsg() - lock_sock() - release_sock() llcp_sock_bind(), same socket - lock_sock() - error - nfc_llcp_send_ui_frame() - if (!llcp_sock->local) - llcp_sock->local = NULL - nfc_put_device(dev) - dereference llcp_sock->dev - release_sock() - return -ERRNO The nfc_llcp_send_ui_frame() checked llcp_sock->local outside of the lock, which is racy and ineffective check. Instead, its caller llcp_sock_sendmsg(), should perform the check inside lock_sock(). Reported-by: syzbot+7f23bcddf626e0593a39@syzkaller.appspotmail.com Fixes: b874dec21d1c ("NFC: Implement LLCP connection less Tx path") Cc: Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp_sock.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index 6cfd30fc0798..0b93a17b9f11 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -789,6 +789,11 @@ static int llcp_sock_sendmsg(struct socket *sock, struct msghdr *msg, lock_sock(sk); + if (!llcp_sock->local) { + release_sock(sk); + return -ENODEV; + } + if (sk->sk_type == SOCK_DGRAM) { DECLARE_SOCKADDR(struct sockaddr_nfc_llcp *, addr, msg->msg_name); From patchwork Sat Jan 15 12:26:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12714371 X-Patchwork-Delegate: kuba@kernel.org 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 E8B0BC433EF for ; Sat, 15 Jan 2022 12:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231153AbiAOM1D (ORCPT ); Sat, 15 Jan 2022 07:27:03 -0500 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]:60816 "EHLO smtp-relay-internal-1.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230459AbiAOM1C (ORCPT ); Sat, 15 Jan 2022 07:27:02 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 7E08E3F1E4 for ; Sat, 15 Jan 2022 12:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642249617; bh=YRVG1n1vJA0XrL2lVGuLt3uwESm9x/YKDmWmaL4GYfI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H3CMewKeO69OXAD8wdQuU4iFH6ILu5Dmvzh5ssQmTv30Kjg+AZiyAXWtLULNrqvDD XOU82J2C9PA4xVhi2rE8aJ/HoequCobV3KOA3B1DKyZ/wb8+hfs33nMinzJq5kTP7R GSaxb+Uyl1LRHsF2eC5Zbb/MGMrrrvurfWKg+R/lcF1nv8N0E2U3zqQTjYDnW+CKlC rjFuneMVKfujNxcmUGsAVF3yAEfl5jlPXhuyVqrzCEjpOkCjS6me0h81LC6A+zPZy+ lN4rMRsbKzRZNbXayaloWEn/d2o8sWqAXckUu4g2sxRQlBmRGADdRXHYiMHWO25RT/ h87ZSCu5Q9dOw== Received: by mail-wm1-f71.google.com with SMTP id j18-20020a05600c1c1200b0034aeea95dacso4461791wms.8 for ; Sat, 15 Jan 2022 04:26:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YRVG1n1vJA0XrL2lVGuLt3uwESm9x/YKDmWmaL4GYfI=; b=Sr9RqMTUWdVEXDnWQmt0LzfCjTDIGxPdhw6TCagY6FJyEqpuJYc27NhjGtbJdsKF+H r05jLDyxQktnf1j5pr7snWDFVdcRsthyobtnvLg8sXgZSPYhiBOSHjibC3Y9H1CEaX7B bRVIdtOxouOhTYDZ9QhMJVtcBDOfd9C4+jWm9lm3Dp9Wg/QSKrItzC4h+abfvYzR3eQl U5dO76l4oOBaDd298tpEry8f0mLONokxR3szwIQONHfWQ3T63XFP8LOtOKoVMbeqSkBl za4QEsjYVYAboYVNXXd5spM613MGcTCHIVv6kAdI/9ae/2N5aR7ur+0Qg+Caa+dZbHYm 4Aag== X-Gm-Message-State: AOAM531gop4K7Qiy1JnJUMqKNmxrjwIok3qSsLtxwq/rCZ/qJf6QmEwc CbufKB15ONSp29nacC+WQEshhSjVmznWvFsYoJ4k0YGY+LQXRgFP/UHMH17+FWHhy0T+klKRPC6 nQdjy9v9NE+ZrKYOxGaZmyQo/Y7tf6OipwA== X-Received: by 2002:adf:f390:: with SMTP id m16mr12347880wro.651.1642249617121; Sat, 15 Jan 2022 04:26:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzprxD4q8/vHQKRv14tzXFqCdIRim3TyjTiDo4rumIOols5/nb1r4v0oXNQ6oWEsRXBRZ4EzQ== X-Received: by 2002:adf:f390:: with SMTP id m16mr12347873wro.651.1642249616997; Sat, 15 Jan 2022 04:26:56 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id bk17sm7878476wrb.105.2022.01.15.04.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jan 2022 04:26:56 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] nfc: llcp: nullify llcp_sock->dev on connect() error paths Date: Sat, 15 Jan 2022 13:26:45 +0100 Message-Id: <20220115122650.128182-3-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> References: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Nullify the llcp_sock->dev on llcp_sock_connect() error paths, symmetrically to the code llcp_sock_bind(). The non-NULL value of llcp_sock->dev is used in a few places to check whether the socket is still valid. There was no particular issue observed with missing NULL assignment in connect() error path, however an similar case - in the bind() error path - was triggereable. That one was fixed in commit 4ac06a1e013c ("nfc: fix NULL ptr dereference in llcp_sock_getname() after failed connect"), so the change here seems logical as well. Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp_sock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index 0b93a17b9f11..e92440c0c4c7 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -764,6 +764,7 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr, llcp_sock->local = NULL; put_dev: + llcp_sock->dev = NULL; nfc_put_device(dev); error: From patchwork Sat Jan 15 12:26:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12714373 X-Patchwork-Delegate: kuba@kernel.org 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 44DD5C43219 for ; Sat, 15 Jan 2022 12:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231268AbiAOM1F (ORCPT ); Sat, 15 Jan 2022 07:27:05 -0500 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]:60814 "EHLO smtp-relay-internal-1.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230448AbiAOM1C (ORCPT ); Sat, 15 Jan 2022 07:27:02 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id CD03F3F1E8 for ; Sat, 15 Jan 2022 12:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642249618; bh=ePWS8huBNB8mOLwzP5l9zhhnqwr/R2aV/N6dfRb+pkA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=vnd9YjeTAkXxpN3SWdBQaa337/49tJieZIqgKEBiUQHWsuzpNxPY34sQ/iKaPtIuy kftQO22UqiTrGMG/MxJhOPjcVk7bvbyyiyfnHPadRsVUnmVuVyzekYEg6y0pSpNseh UjijZ9YXB3JbAhYa1ceOkL/G50f/h+jenmGykR92DiqW09cjMLhSDFVujHC3cD4/t+ upyEjk3kN5x12CDupekVUT5Iyc5RByF5b2rOo9AC2sUWd2t2Dty9qc1oHxsm3mp+RE 20e5f0hNC88RcwqBVUJMuuIt1OEzULtpV4MaY2hfytZ1WWHFVvmX7TTDyzLTwJgS1O wpHmt3U1o0LUg== Received: by mail-wm1-f71.google.com with SMTP id m9-20020a05600c4f4900b0034644da3525so7326026wmq.3 for ; Sat, 15 Jan 2022 04:26:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ePWS8huBNB8mOLwzP5l9zhhnqwr/R2aV/N6dfRb+pkA=; b=rIJG1VsSIN8aMZB7ooMGI2YltfGYYfaPlMPGCYxSLzD+IEGtjE2kAupKfO7GYM7U+n gOeobtYh55j8+deQCV8LeJxt7oQWi8IgFmHd94sFQS+BehIK5txAK3rReFxq4vgiF0ow dm4Sw5bDhS7MFcnTHev9cucoKAjC/LfWEdzp2ilgVpcDXss8kHMxmrS6FZu+/W0QvC4Z 9ytCeeS3CPotYHeBq03IfRwh/ME7kgVkJP2fj8/nFybdcYtSy3dGWOOHj2vfCWYT/u4B 9k/cYA298M8LTrn+xm0x2T0SdIYKB/vboGmitQf4ofgkk+vkYoqzZYKq7XFXfsqoONzt v2GQ== X-Gm-Message-State: AOAM530jjuAQkQ4S+pharybp/OGS7dDdT2DOl81zTOBfTxXmb5cqZOKy GELQDy/+MWPZd2KcnB3bf+PlOiKsoWGbAtqQ5wjpONrfk17nfrdEVRFhcEbAPasXcZf+4b34ZZU MrzoB9CWRg3vfLOQvSu2QDXTQiFkhKAzooQ== X-Received: by 2002:a5d:6f0a:: with SMTP id ay10mr12121173wrb.191.1642249618562; Sat, 15 Jan 2022 04:26:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbQP4Q1giAJ4uAlzrN0vo+MIFiQCq0DOWWfo4iYlUpIw0pSA9ah1HXa5NlBGI3l4j4jOixug== X-Received: by 2002:a5d:6f0a:: with SMTP id ay10mr12121168wrb.191.1642249618445; Sat, 15 Jan 2022 04:26:58 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id bk17sm7878476wrb.105.2022.01.15.04.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jan 2022 04:26:57 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/7] nfc: llcp: simplify llcp_sock_connect() error paths Date: Sat, 15 Jan 2022 13:26:46 +0100 Message-Id: <20220115122650.128182-4-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> References: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The llcp_sock_connect() error paths were using a mixed way of central exit (goto) and cleanup Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp_sock.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index e92440c0c4c7..fdf0856182c6 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -712,10 +712,8 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr, llcp_sock->local = nfc_llcp_local_get(local); llcp_sock->ssap = nfc_llcp_get_local_ssap(local); if (llcp_sock->ssap == LLCP_SAP_MAX) { - nfc_llcp_local_put(llcp_sock->local); - llcp_sock->local = NULL; ret = -ENOMEM; - goto put_dev; + goto sock_llcp_put_local; } llcp_sock->reserved_ssap = llcp_sock->ssap; @@ -760,11 +758,13 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr, sock_llcp_release: nfc_llcp_put_ssap(local, llcp_sock->ssap); + +sock_llcp_put_local: nfc_llcp_local_put(llcp_sock->local); llcp_sock->local = NULL; + llcp_sock->dev = NULL; put_dev: - llcp_sock->dev = NULL; nfc_put_device(dev); error: From patchwork Sat Jan 15 12:26:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12714380 X-Patchwork-Delegate: kuba@kernel.org 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 2118DC433F5 for ; Sat, 15 Jan 2022 12:28:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230448AbiAOM23 (ORCPT ); Sat, 15 Jan 2022 07:28:29 -0500 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:47530 "EHLO smtp-relay-internal-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbiAOM1E (ORCPT ); Sat, 15 Jan 2022 07:27:04 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (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) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 9482A402B3 for ; Sat, 15 Jan 2022 12:27:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642249620; bh=XW443xLXNMd7fKnAwsj5MsweNUN/P9g1RwySZfWsL7A=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kAyFx/JNGNxvnqNVk79wHaTbGDFtnx4sATPuW9MUSya73fwOhaTTQX6fMDvfiyixf 3Lh5AjlQXxmiwgAVGb4XaFUPtfywNOsGtQ/7fjQp7gGM+Vjw2JUmmCGevwxHM/cP4w EFJgnrFxn9CxXugv9iJt4ayv3z67Qo6gJ4GwNH/3d5AzTnOarPeP08r+VUO+s4uWcY KY8Yvxcg4QSymHZu0M2vDTNmUfDa+orosq696XND6t4HumAq83hgUPcMryUne1h02o g4Jdg5GDk5UGwE7inGND/sTKRImBpAip73040+BWCTbrDIBb9ndoNqqsdsvi57Pep9 6cO/+YlHWzLig== Received: by mail-wm1-f70.google.com with SMTP id bg16-20020a05600c3c9000b0034bea12c043so509252wmb.7 for ; Sat, 15 Jan 2022 04:27:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XW443xLXNMd7fKnAwsj5MsweNUN/P9g1RwySZfWsL7A=; b=MgB0VMOD8JLKaNmFsmoQ+CjDSX2QDZsl38+bLI87OiNAhNvkOpMzPj8nHSIihn/SeZ 2x8ZgoKbSsWCM8dR5DW7G+k70mKO+VAKq39D8IrU7MSDQyIrUGE5uSERn8JbyeBt+AgU BrVvueh52ZBBmFPGKQJxxma6ZMZMrHx9iT4PgLS3vWpvAdu4ZvfDjg6xff5Rcqa4cIsi AASXrtdgDv3SpcvQhJJdd6ykKaTQ5oTwpyrvXRagm/98Ba086XokyYszzUZ/qJ+fI08r 3eg64oUnpkKqkrL1YBT4gD1/d4NnTQ+iGeVKhLYHuJn/ikc63f11XFlMznI3/JL+JM3C PBCw== X-Gm-Message-State: AOAM531qyXKNBGm9B6UYw0iLoO4cKQSgpy07O6VNQQN30uP1E+O6YLXo b+5DD7Lqv//rEcPJjbJLfi2QeHnWZUnAJH3gnrXA+vdJB0U29LSswGFnSWTViHyXe9aPNjvj6p+ GX0oxKILNt8yi01h2u7aUc+YtVSeEMJMVKw== X-Received: by 2002:adf:e810:: with SMTP id o16mr918249wrm.148.1642249619802; Sat, 15 Jan 2022 04:26:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmyGxwz6Gt13RegtMp19MSWLXNTMDHakRk1jf3lOXKJSBHxsTjjfU5CLCgc4+yB+jzAl2W2w== X-Received: by 2002:adf:e810:: with SMTP id o16mr918237wrm.148.1642249619675; Sat, 15 Jan 2022 04:26:59 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id bk17sm7878476wrb.105.2022.01.15.04.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jan 2022 04:26:58 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/7] nfc: llcp: use centralized exiting of bind on errors Date: Sat, 15 Jan 2022 13:26:47 +0100 Message-Id: <20220115122650.128182-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> References: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Coding style encourages centralized exiting of functions, so rewrite llcp_sock_bind() error paths to use such pattern. This reduces the duplicated cleanup code, make success path visually shorter and also cleans up the errors in proper order (in reversed way from initialization). No functional impact expected. Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp_sock.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index fdf0856182c6..c9d5c427f035 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -108,21 +108,13 @@ static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) llcp_sock->service_name_len, GFP_KERNEL); if (!llcp_sock->service_name) { - nfc_llcp_local_put(llcp_sock->local); - llcp_sock->local = NULL; - llcp_sock->dev = NULL; ret = -ENOMEM; - goto put_dev; + goto sock_llcp_put_local; } llcp_sock->ssap = nfc_llcp_get_sdp_ssap(local, llcp_sock); if (llcp_sock->ssap == LLCP_SAP_MAX) { - nfc_llcp_local_put(llcp_sock->local); - llcp_sock->local = NULL; - kfree(llcp_sock->service_name); - llcp_sock->service_name = NULL; - llcp_sock->dev = NULL; ret = -EADDRINUSE; - goto put_dev; + goto free_service_name; } llcp_sock->reserved_ssap = llcp_sock->ssap; @@ -132,6 +124,19 @@ static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) pr_debug("Socket bound to SAP %d\n", llcp_sock->ssap); sk->sk_state = LLCP_BOUND; + nfc_put_device(dev); + release_sock(sk); + + return 0; + +free_service_name: + kfree(llcp_sock->service_name); + llcp_sock->service_name = NULL; + +sock_llcp_put_local: + nfc_llcp_local_put(llcp_sock->local); + llcp_sock->local = NULL; + llcp_sock->dev = NULL; put_dev: nfc_put_device(dev); From patchwork Sat Jan 15 12:26:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12714372 X-Patchwork-Delegate: kuba@kernel.org 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 2DFE1C433F5 for ; Sat, 15 Jan 2022 12:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231294AbiAOM1F (ORCPT ); Sat, 15 Jan 2022 07:27:05 -0500 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]:60826 "EHLO smtp-relay-internal-1.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbiAOM1D (ORCPT ); Sat, 15 Jan 2022 07:27:03 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 27F583F1E5 for ; Sat, 15 Jan 2022 12:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642249622; bh=yrlNFOS5f9IRjvA5fm0IVEgclHgNp68QGUe5Q3pp8Vc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HmgUJJgucw4IqWlwOu8h94ZI16bOPZ28Mgi1y+Tsj5jjeyEYwQkz8Ki8Q5zbmkVcm 4Ei1Xx647ng7xyj9RBOnS7pgwJYjgNA8GU+o+0Kv5+iDtxQCBzI5tJ1T+eZ3y7L3hG jg9oxDAO7ROflhpD/sozM2kjuq2rAsHBxxJ2Le0KAjX396u7JjxfOaD2KLghGCBRvv AUDjpaNKUng4m7lAUyz9Urqr3YsMDa/JY03BVSPjolsOwGj8V2O+jxuQ8or3O8Pcy/ Eglqm7HbdUMBgy4kQZqrSNCRyuBHwtAG1xfwL+kn6/ouRsWVMH3SfoSihiUv2zbbgJ 8rtxWJieGCJug== Received: by mail-wm1-f71.google.com with SMTP id a3-20020a05600c348300b0034a0dfc86aaso7203696wmq.6 for ; Sat, 15 Jan 2022 04:27:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yrlNFOS5f9IRjvA5fm0IVEgclHgNp68QGUe5Q3pp8Vc=; b=Jmw+O9NHV3K+2XxDAaElBXUC4vxb5q6RiFrkY+CeaCCTUo+NBlyOPb0jp+hhwr2fwW wQT3yT9pMqbyBds1G051jkTiKyj0vZ0rOXj/K9VPNtWWEZpMexYEYNj+AXbqiv/PpE2u GyY/Q9o4tXtVCyeiyz29tI+YiRA1Y/UGSdCrBGv9xkkIZ9sgo/XhFdW3VdeyqolIhTr2 wzmEYD9ghGLn4bcro+K7D08GxhpF5w06GTyEDn/8nNJdeqZCb71STkGgDGJkmbpGhOMJ EK/ro6lu9/NKevoSvGo22dc0n3SbLwJOuMcNh3UQXyhdUhS9PghfJrvTD4u4RIPLHaq8 vfrQ== X-Gm-Message-State: AOAM53391uFeak9TXuHW9kCeM5MwSmayx0mrM7DXMOE8ZoCHDiA3YiPb IRvgXC/9NQdjaCdsZ2XeDpq2GZFOMsCXY0nWuG4xG3mwpULXR4YsCieBBkWgo6uA0szfQM2D+QS cO+MSINK5dRar/Z7iKELv3qMMMnVUeENQog== X-Received: by 2002:adf:f0d1:: with SMTP id x17mr12129014wro.223.1642249621083; Sat, 15 Jan 2022 04:27:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuosj48Z96wc9CpVVg353GMRvCJEBxDaoKE+PY1MPfJ8vkd7s+FLfB9jQET/3Y31fE7LgFfQ== X-Received: by 2002:adf:f0d1:: with SMTP id x17mr12129002wro.223.1642249620903; Sat, 15 Jan 2022 04:27:00 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id bk17sm7878476wrb.105.2022.01.15.04.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jan 2022 04:27:00 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] nfc: llcp: use test_bit() Date: Sat, 15 Jan 2022 13:26:48 +0100 Message-Id: <20220115122650.128182-6-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> References: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use test_bit() instead of open-coding it. Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c index 5ad5157aa9c5..b70d5042bf74 100644 --- a/net/nfc/llcp_core.c +++ b/net/nfc/llcp_core.c @@ -383,7 +383,7 @@ u8 nfc_llcp_get_sdp_ssap(struct nfc_llcp_local *local, pr_debug("WKS %d\n", ssap); /* This is a WKS, let's check if it's free */ - if (local->local_wks & BIT(ssap)) { + if (test_bit(ssap, &local->local_wks)) { mutex_unlock(&local->sdp_lock); return LLCP_SAP_MAX; From patchwork Sat Jan 15 12:26:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12714377 X-Patchwork-Delegate: kuba@kernel.org 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 7BA1DC433EF for ; Sat, 15 Jan 2022 12:27:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230471AbiAOM1L (ORCPT ); Sat, 15 Jan 2022 07:27:11 -0500 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]:60834 "EHLO smtp-relay-internal-1.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbiAOM1D (ORCPT ); Sat, 15 Jan 2022 07:27:03 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (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) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id AFE203FFD9 for ; Sat, 15 Jan 2022 12:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642249622; bh=k1fbxXsPvGzkuFTuMvPObzXkHdaiukX+p5UqHJ6OWe0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b4h6sU01ezgtViqkPX5VjAUI5cQBYk1VW8y5ymo//qJonPQhkGJXyW3jeBVC53Z7n pVO2nrrpttg62+0I+DXzKVxEQGMySjAGVaJNUYN9arOKtx2hXH2pLr2JHFOlFRoOD3 5JL3ple6uYK5KDlAv+QOBCSJJ2Uea4LGQN2Or8b4kMthZzlpJ2cCRcOhn5zWTmy2Ci mrvAsIyCGDXvchcgTKA4EZbJ/Rao/70kMsczoVBcfs0lNiwOfyAIgdTxqks5H+e0UW VsfAW40/Cl9DXbU7DMuKi6lV/YpHioFtNfWSo8a6YV3147n+SZYZhZ4qCfQHaNLhjl oVp0gI82hYdDA== Received: by mail-wm1-f72.google.com with SMTP id o185-20020a1ca5c2000000b003478a458f01so8105048wme.4 for ; Sat, 15 Jan 2022 04:27:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k1fbxXsPvGzkuFTuMvPObzXkHdaiukX+p5UqHJ6OWe0=; b=eU1W51E1dVKfRcaprI1OoT63lXqXZY7zD0tk6zK2a6URf+jdAt1iI3iaWkJFOzOsfy x29zPGFDNCr4cCDwPJt7yJiRS7xFtYDNDPl88dRRPtG9GEZrBZE0Eu2zkRCl6KBv29rz nLnjV5sALOmkPOKSJTRt8LVCnZaG103Ophc0XTX+F/9oOxORZ1SGeDdC1Mle6qwBocng +zSEQfN5jJTUGWfuMX3D711zPE8ukQFXfWvHT9DvmtLcyaUTCslk7dEJobb696AMVNxY yKOGGRcleCEGijNM7lAiRqyEWssV+l6pevj8HbWXnKHL4oYlZJjy3K0a0toyZYT155jv I1Mw== X-Gm-Message-State: AOAM533Gu7wAdEpBGkJuMRclrJSvE6ngpnB14cUMvJsw74o7IGaG8F9L hErX13lgxTIPgUnC8vBYZR4F0cB/AQXQi4RWaLJwAQHajH7yQP+RkNt/KHQmlCX3R3F1TOKo1QP gh4pGbf/ks/eYyv6fbvWjSe0oUGhTN62DRA== X-Received: by 2002:adf:f9cb:: with SMTP id w11mr12363535wrr.106.1642249622358; Sat, 15 Jan 2022 04:27:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXCX9qNHfjpMa31u9yvOahIXiFLP9Aqa1v2s/wcOF8lsTtZYY/Ms1xdIFV/FMREuwupnobnw== X-Received: by 2002:adf:f9cb:: with SMTP id w11mr12363520wrr.106.1642249622169; Sat, 15 Jan 2022 04:27:02 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id bk17sm7878476wrb.105.2022.01.15.04.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jan 2022 04:27:01 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/7] nfc: llcp: protect nfc_llcp_sock_unlink() calls Date: Sat, 15 Jan 2022 13:26:49 +0100 Message-Id: <20220115122650.128182-7-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> References: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org nfc_llcp_sock_link() is called in all paths (bind/connect) as a last action, still protected with lock_sock(). When cleaning up in llcp_sock_release(), call nfc_llcp_sock_unlink() in a mirrored way: earlier and still under the lock_sock(). Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp_sock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index c9d5c427f035..5c5705f5028b 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -631,6 +631,11 @@ static int llcp_sock_release(struct socket *sock) } } + if (sock->type == SOCK_RAW) + nfc_llcp_sock_unlink(&local->raw_sockets, sk); + else + nfc_llcp_sock_unlink(&local->sockets, sk); + if (llcp_sock->reserved_ssap < LLCP_SAP_MAX) nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap); @@ -643,11 +648,6 @@ static int llcp_sock_release(struct socket *sock) if (sk->sk_state == LLCP_DISCONNECTING) return err; - if (sock->type == SOCK_RAW) - nfc_llcp_sock_unlink(&local->raw_sockets, sk); - else - nfc_llcp_sock_unlink(&local->sockets, sk); - out: sock_orphan(sk); sock_put(sk); From patchwork Sat Jan 15 12:26:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12714376 X-Patchwork-Delegate: kuba@kernel.org 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 8DF17C433F5 for ; Sat, 15 Jan 2022 12:27:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231391AbiAOM1N (ORCPT ); Sat, 15 Jan 2022 07:27:13 -0500 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:47542 "EHLO smtp-relay-internal-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231290AbiAOM1G (ORCPT ); Sat, 15 Jan 2022 07:27:06 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 9E3AB40033 for ; Sat, 15 Jan 2022 12:27:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642249624; bh=Mdsn7AT474MZc2MQVfRJDSMS8EOfClYXR9EYCiW/6uw=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U7pzAp9DK5Mmm1HPgDPU2mqOab1Df4U3g5TVODAipGIIPqZA+zLatKQF54Vp5NHnx ofHbHDjlHzrNLjV+4uUMnxVhk+R6eyCzVAMwQX0PDL5sE3V/C/oyXtyaP3Q83ivm/e 3E303UrR/APJqkf/blzKe5KlokDLv5hK/faLBYkVT0/QUGwIKUuQvyI1ccq6hNEQpC SKablJMbews5RzZR3rr6yhw2eRReNK2kgvN6cU5bDf8jXGgJeCHa3BOjsht8SABbsy SprKH+l/KT4f8qVbc5wCiHMP6J0yEliK8t9hUZ8ouHPDaAx53p9dTjrEeQN4l/RhM6 s1GLHltuzyPrg== Received: by mail-wm1-f71.google.com with SMTP id 20-20020a05600c22d400b00349067fe7b7so3590924wmg.5 for ; Sat, 15 Jan 2022 04:27:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mdsn7AT474MZc2MQVfRJDSMS8EOfClYXR9EYCiW/6uw=; b=xxNEGglWmlO9DaQHPa7e9kFBkAt8HaG+k1VdwFQLFoMimj3kkqR5dCL5kaf9Y9rNUO 8pU6dHitDXQsXPsZ6Pqg4HcXHTvePuAsrw/1NHpLwnKYAQa9kgrCAHMa8FIR4ZveOGpl K0Rt0sfLdOJhOyULRLEBpUPvsWT5KuMqYODtcYcHQOX8rZmW9VEJWU89cSMJQoH2jL6f 7tN8b4sBZK5j/3lTRgTqboXKlwZlJP33D64Sv1K2VrnJd5VhAJcbOUdzULjHW4/nxewX LtXjwBizXhFXSZRCq+8UZvy0YjgIR+jDxJVu83Uq4upU8l/NEau9IOcGh8VgCxIFq3mx vYyA== X-Gm-Message-State: AOAM533KAr6YhMU5/lrx/7Zc7a4IcT19zxp5Gx9LosrdkEiEbpmDEAWg g+p+sZfmz9RJXO/v6h1kBWKsltfUXHkjLPAHS9/BX/1bLaUZqACH6gdSKOuFkzLq6DdUAdwbIR0 IQf3q00DlpieAFXp23ZIi1IwrIyFOhcnJqQ== X-Received: by 2002:adf:f0c8:: with SMTP id x8mr12500718wro.8.1642249623657; Sat, 15 Jan 2022 04:27:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+9/EJPNvF2Lg8TPggKvvKyZTnv0CkGSej/R9OMq8UBJ+esAn4SYxe7sYrdb7br5pj2o5aOQ== X-Received: by 2002:adf:f0c8:: with SMTP id x8mr12500703wro.8.1642249623522; Sat, 15 Jan 2022 04:27:03 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id bk17sm7878476wrb.105.2022.01.15.04.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jan 2022 04:27:03 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/7] nfc: llcp: Revert "NFC: Keep socket alive until the DISC PDU is actually sent" Date: Sat, 15 Jan 2022 13:26:50 +0100 Message-Id: <20220115122650.128182-8-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> References: <20220115122650.128182-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This reverts commit 17f7ae16aef1f58bc4af4c7a16b8778a91a30255. The commit brought a new socket state LLCP_DISCONNECTING, which was never set, only read, so socket could never set to such state. Remove the dead code. Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp.h | 1 - net/nfc/llcp_core.c | 7 ------- net/nfc/llcp_sock.c | 7 ------- 3 files changed, 15 deletions(-) diff --git a/net/nfc/llcp.h b/net/nfc/llcp.h index d49d4bf2e37c..c1d9be636933 100644 --- a/net/nfc/llcp.h +++ b/net/nfc/llcp.h @@ -6,7 +6,6 @@ enum llcp_state { LLCP_CONNECTED = 1, /* wait_for_packet() wants that */ LLCP_CONNECTING, - LLCP_DISCONNECTING, LLCP_CLOSED, LLCP_BOUND, LLCP_LISTEN, diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c index b70d5042bf74..3364caabef8b 100644 --- a/net/nfc/llcp_core.c +++ b/net/nfc/llcp_core.c @@ -737,13 +737,6 @@ static void nfc_llcp_tx_work(struct work_struct *work) print_hex_dump_debug("LLCP Tx: ", DUMP_PREFIX_OFFSET, 16, 1, skb->data, skb->len, true); - if (ptype == LLCP_PDU_DISC && sk != NULL && - sk->sk_state == LLCP_DISCONNECTING) { - nfc_llcp_sock_unlink(&local->sockets, sk); - sock_orphan(sk); - sock_put(sk); - } - if (ptype == LLCP_PDU_I) copy_skb = skb_copy(skb, GFP_ATOMIC); diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index 5c5705f5028b..4ca35791c93b 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -641,13 +641,6 @@ static int llcp_sock_release(struct socket *sock) release_sock(sk); - /* Keep this sock alive and therefore do not remove it from the sockets - * list until the DISC PDU has been actually sent. Otherwise we would - * reply with DM PDUs before sending the DISC one. - */ - if (sk->sk_state == LLCP_DISCONNECTING) - return err; - out: sock_orphan(sk); sock_put(sk);