Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4060010pxb; Mon, 4 Oct 2021 16:27:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+WlOVu7Mh/S5ZapSddKe1G4K/08HdKZGAJGkpQvadisq0OcDY51PY5iB6HwdO9AFjLIh9 X-Received: by 2002:a17:906:2da2:: with SMTP id g2mr20794965eji.38.1633390055111; Mon, 04 Oct 2021 16:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633390055; cv=none; d=google.com; s=arc-20160816; b=uzNLQmWxraJt3485xIHNRb0ypYL6ZjAWRplG+B81iFjKm0shXMgedHgQW3BQGPkkRD k9o3DoET2iLsG1zLdESM26oEpv/SmBLYu76PXbGwshCdm2Wnl5N5LP8GxxcRkq43NXgI z6mWEV8THRc4CXis+hujgMgSfJLBMfY/W6v0xdV/ypfNr8kHcygbhUIVu75Oqql3Y5nk agam9Iq2eVAw4Ux7PLW9xUG6AVWBr7OfFWIDFAd5iNLG0f+hh3FEY4S+zrfNcjiPaPRB ueRXcwjzR+76PriaPQef2UJXOfY9FI2fG1WOImBKBSBG4zHt5RvZHEqg80URa+DvZeMq bcMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=+fT+aA8O5oRqS8Fx8O+K4w9xvhEfwcMTbFUqJDULxaY=; b=XkjSBqKKDtO3KZx2JAd8Rfx20PeMYAb7YomimBFGfJB33OxJT098CqGpXhYrOzHVN3 S9gdiKqD81mEYFGWPoiww3Mpy8mRQAdDcIMVEvgRd9J0gT4+GSmithYhKxcOK+EeDIRE dC+mDQSrvG7XS8iOmZa0GdqgTweKGRH6Mb+PwyuOeShvnaZVp3DZVw20BoGylY14Mzah I+saWiLOCpyXiiPPviwoNYu59laBjg0WC+S4h1hmQoCln5WRsBIZCh6mWvfN3qYPDJiw qWfQ6sXbOOa6f04Ex/AgiC8WRfGBE+ehEMMrrI+CHgrDv16eUcbv0lPZo+hEtlV5aCAF jQgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cB8begJI; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u4si21783761ejt.81.2021.10.04.16.27.11; Mon, 04 Oct 2021 16:27:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cB8begJI; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 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 S237086AbhJDSN7 (ORCPT + 99 others); Mon, 4 Oct 2021 14:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236050AbhJDSN6 (ORCPT ); Mon, 4 Oct 2021 14:13:58 -0400 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDC85C061745; Mon, 4 Oct 2021 11:12:09 -0700 (PDT) Received: by mail-qk1-x72a.google.com with SMTP id 73so17380663qki.4; Mon, 04 Oct 2021 11:12:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=+fT+aA8O5oRqS8Fx8O+K4w9xvhEfwcMTbFUqJDULxaY=; b=cB8begJI5ATh6WUeF3PsZL0eN0zkI5dsdFYEZsxDXbahwFjHCE1LT8VFlsj9Lzs7/j Jmu/pnTyPj5S+Fm/F9qYXTzyt8PT95g2kYwLN9j+Tyu+yiMElJlKLkLaso0lI5fd8zOQ 8aikJdx6bbwK0b4VlPhSQGhg3iUjzqBBi0LBltW4vu8eeDkG4nF6JyhWEyPQbE4QM4x6 e5iIa+gy3aim9dxo2/Lhxkkdm/9LBYhyL/YErgBSFkwgRcBPqEnGsPjCkdX4bTXXD6Am uXRC8r/AvgiBFtEY8N7CPtTQmEtAR6muZNgeF1XFRg1hGD1UHOSUVA5Wk6j3ANGQ+glD RaIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=+fT+aA8O5oRqS8Fx8O+K4w9xvhEfwcMTbFUqJDULxaY=; b=5fLsraFjhG1lwxIgZiT6OMdPZuSsZFMG6V9Fpvss3WHUzx1MkW0IAIV1njH8q5w+wW h7kA1gtKm8nKS3R3Oxrluqpeg+2ixEc/mf1HDRirpf2DPHo6o/NPczJmkWhxn5OOAA0o LgntKCnhtLyVX/fswc229A6aC3NvMSWJjmb0pxS2hl5c8O5IsH15dzkVOdZKewEj46WM BfjDrZ2i3Y0gRl7xee7QYEY/zGDlBNtsCyPNX8wsFxA7sqqYuQMAPK9W/M3KgAv9+GXR Ef2yNm8FuBtYAp3i05joTY+4+ROBjMxf4xuN64uTlw9Bi3wsmuzF9VrVsF4m8x3Yecpc ho6g== X-Gm-Message-State: AOAM531teUz6KYVY3PT45BW5edOr1hXdfpFAD1Oh6VTFfBcs61eeiVaj o0VQlTkC/+ulBB52nc2WIb4dRIbxPB/HwM2GLSo= X-Received: by 2002:a37:e14:: with SMTP id 20mr11478184qko.250.1633371128922; Mon, 04 Oct 2021 11:12:08 -0700 (PDT) Received: from [192.168.4.191] (pool-72-82-21-11.prvdri.fios.verizon.net. [72.82.21.11]) by smtp.gmail.com with ESMTPSA id g12sm9179316qtm.59.2021.10.04.11.12.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Oct 2021 11:12:08 -0700 (PDT) Subject: Re: [PATCH 1/2] Bluetooth: call sock_hold earlier in sco_conn_del To: Marcel Holtmann Cc: Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Jakub Kicinski , linux-bluetooth , "open list:NETWORKING [GENERAL]" , open list , eric.dumazet@gmail.com References: <20210903031306.78292-1-desmondcheongzx@gmail.com> <20210903031306.78292-2-desmondcheongzx@gmail.com> <7AEB2618-111A-45F4-8C00-CF40FCBE92EC@holtmann.org> From: Desmond Cheong Zhi Xi Message-ID: <1203215b-13bf-ce0c-ef23-5664544607a1@gmail.com> Date: Mon, 4 Oct 2021 14:12:07 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <7AEB2618-111A-45F4-8C00-CF40FCBE92EC@holtmann.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Marcel, On 10/9/21 3:36 am, Marcel Holtmann wrote: > Hi Desmond, > >> In sco_conn_del, conn->sk is read while holding on to the >> sco_conn.lock to avoid races with a socket that could be released >> concurrently. >> >> However, in between unlocking sco_conn.lock and calling sock_hold, >> it's possible for the socket to be freed, which would cause a >> use-after-free write when sock_hold is finally called. >> >> To fix this, the reference count of the socket should be increased >> while the sco_conn.lock is still held. >> >> Signed-off-by: Desmond Cheong Zhi Xi >> --- >> net/bluetooth/sco.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c >> index b62c91c627e2..4a057f99b60a 100644 >> --- a/net/bluetooth/sco.c >> +++ b/net/bluetooth/sco.c >> @@ -187,10 +187,11 @@ static void sco_conn_del(struct hci_conn *hcon, int err) >> /* Kill socket */ >> sco_conn_lock(conn); >> sk = conn->sk; > > please add a comment here on why we are doing it. > So sorry for the very delayed response. I was looking through old email threads to check if my recently resent patch was still necessary, and just realized I missed this email. This patch was merged into the bluetooth-next tree before your feedback came in. Would you still like me to write a separate patch to add the requested comment? Best wishes, Desmond >> + if (sk) >> + sock_hold(sk); >> sco_conn_unlock(conn); >> >> if (sk) { >> - sock_hold(sk); >> lock_sock(sk); >> sco_sock_clear_timer(sk); >> sco_chan_del(sk, err); > > Regards > > Marcel >