Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2927065pxb; Sun, 29 Aug 2021 07:54:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxjbb2DI9icPK4XP0pA2se9hLfiRaNOxTAkGbySP/+OHD+1XrkNkN55H61Vj+EsLV0z78N X-Received: by 2002:a05:6638:14cf:: with SMTP id l15mr2864213jak.8.1630248883623; Sun, 29 Aug 2021 07:54:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630248883; cv=none; d=google.com; s=arc-20160816; b=m0UOtB3fEHnHKshalE3rujEe0TS/MNk66rXLPtcllq/BfQ+UaTsVOrWp9sQaFvyxju 9YrNlEuBQ4w2xWV+vKUk0+/NDJFGPNMru3NAE8DYGIQ4YqlYP9NxJccGiFlr1bUxBoMu EYAtsaY43P0aFAwbqxR1gveKwepM9IQlptL26SEWJAsDvWyxJQX12dTCwioQv9AfHQDq G69VUCqXAVngYdbkc4uJVzYc27CZrvY4dKjTT11WhmLBljYxovH67hVXTmQn6qrn28JJ v4Mq/6yWwD4cYDjE+qHzvb08TIYNo5bkFZi6revzflU+4WKc8E/enYXu3+LLRsd9Jnhx sYbg== 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=gZ/nenUcj9mad1OmYCCfvZwnAJEnEhtMP/nmkyY6NOM=; b=NnnG5bHi0Qfv0CBd5eVNvJSJca0u9+Z88A8j3XCtW0fx0ZfMrUX5O5BfhLUfU5SQub tRBoDgplFcQt4LkIiukCPpSPBONJlBnsKQ4otdoxXKbrJCFUb9mAGBL2zjiTao9OUpMO +Xwn+vbHylg/ctwoMyxn71/UMml1Qn4aDMlPXkF3nMr9GSTVe0kmbBhTJlR2qDqsIps2 L6BkR5wpH5gJDfGYJ+MWX1YFWMpnLuHQlR7iJXtFx+itpeH/En1GMKq6IzZwdzdasVYe uePzQDDyh3b01rzP//zgpsmZ07N174jilK1egT+Zun0N2QihrrAX5ldmzgD3FjlI/dJa 9yag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SqRgue5J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 t39si14511780jal.96.2021.08.29.07.54.30; Sun, 29 Aug 2021 07:54:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=20161025 header.b=SqRgue5J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S235495AbhH2OyH (ORCPT + 99 others); Sun, 29 Aug 2021 10:54:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235452AbhH2OyG (ORCPT ); Sun, 29 Aug 2021 10:54:06 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5C2BC061575; Sun, 29 Aug 2021 07:53:14 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id u11-20020a17090adb4b00b00181668a56d6so8233224pjx.5; Sun, 29 Aug 2021 07:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=gZ/nenUcj9mad1OmYCCfvZwnAJEnEhtMP/nmkyY6NOM=; b=SqRgue5J5BHXPuOWjfah7o4X0Mg0vV+2AHpa9GzTTbkeNGDaZCsDmBehausz0MNYaF bHhlG8PxIgz2iW1Cmo83vEep3rsZzrKGQSKmJLNtqciTub6iPZW9hUbN2m663tEGgJJ/ /FnW4ospoz5MU7i3+pu/Rn6ETpJgnh5Ywarwg0YaqydcTOfpuKuZX3F+mPTZSHzvgRV8 x8i94JuHtgJkk1kdp7CTFd7iUM9edyroXd9FcO8Pmmv59kNgxtwFLk+NiyqaQhUmhco1 kVpiVNfRaNOiiBQ4WMphk+v0OpjwgoSfhPhLYWwbBMkHC0HirYofOnTJ1TNX/V5LhaCN eUCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=gZ/nenUcj9mad1OmYCCfvZwnAJEnEhtMP/nmkyY6NOM=; b=UO+wcUt/hCekNK7lyRaPmyAyEywyV7oGP8rZN6s+gNdq2M6cc3C1KftphMTs30Adnn J85ctOm1eRTlL7atHDwwHmHw8UrwyuH39enYaSAz+XQbxjdGDyiU/Dp7tremsSHahaGc AyGoKhZnhLOSAeApLdDXpJjiNQHrygspbr21MqsFa64qHiNszWw/ZitsHipeAAcUNt9D iMWSCu+UgxfuTfWVVpQg+783jU7zhpS1xewf4l1GRDFHMUnnuJKMBHQcQjfmbdCPNrDm cmgvDCxFGSRlcA+bpQYK9xzxg1DzhOaNQhTtbjN8FO6SE8uYTYDstnX+r1m0un6beLUW TspQ== X-Gm-Message-State: AOAM533gz1+KhrhVMaUalwxRvZKwIQqcqG8buBLDyRt5Tk8Z0VHZO8Md gz5MfpB5VmLnHHbhbOGkyNg= X-Received: by 2002:a17:90a:e001:: with SMTP id u1mr30902387pjy.183.1630248794241; Sun, 29 Aug 2021 07:53:14 -0700 (PDT) Received: from [192.168.1.237] ([118.200.190.93]) by smtp.gmail.com with ESMTPSA id n14sm19456487pjm.5.2021.08.29.07.53.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Aug 2021 07:53:13 -0700 (PDT) Subject: Re: [syzbot] KASAN: use-after-free Write in sco_sock_timeout To: Hillf Danton Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, luiz.von.dentz@intel.com, syzbot , syzkaller-bugs@googlegroups.com References: <000000000000b2725705ca78de29@google.com> <20210827011931.2323-1-hdanton@sina.com> <20210829082929.2897-1-hdanton@sina.com> From: Desmond Cheong Zhi Xi Message-ID: <11a30bc1-574f-aa1a-21d6-b886de9fc981@gmail.com> Date: Sun, 29 Aug 2021 22:53:10 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210829082929.2897-1-hdanton@sina.com> 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-kernel@vger.kernel.org On 29/8/21 4:29 pm, Hillf Danton wrote: > On Fri, 27 Aug 2021 15:58:34 +0800 Desmond Cheong Zhi Xi wrote: >> On 27/8/21 9:19 am, Hillf Danton wrote: >>> On Thu, 26 Aug 2021 09:29:24 -0700 >>>> syzbot found the following issue on: >>>> >>>> HEAD commit: e3f30ab28ac8 Merge branch 'pktgen-samples-next' >>>> git tree: net-next >>>> console output: https://syzkaller.appspot.com/x/log.txt?x=13249c96300000 >>>> kernel config: https://syzkaller.appspot.com/x/.config?x=ef482942966bf763 >>>> dashboard link: https://syzkaller.appspot.com/bug?extid=2bef95d3ab4daa10155b >>>> compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.1 >>>> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=16a29ea9300000 >>>> >>>> The issue was bisected to: >>>> >>>> commit e1dee2c1de2b4dd00eb44004a4bda6326ed07b59 >>>> Author: Desmond Cheong Zhi Xi >>>> Date: Tue Aug 10 04:14:10 2021 +0000 >>>> >>>> Bluetooth: fix repeated calls to sco_sock_kill > > To fix the uaf, grab another hold to sock to make the timeout work safe. > > #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git e3f30ab28ac8 > > --- a/net/bluetooth/sco.c > +++ b/net/bluetooth/sco.c > @@ -190,15 +190,14 @@ static void sco_conn_del(struct hci_conn > sco_conn_unlock(conn); > > if (sk) { > - sock_hold(sk); > lock_sock(sk); > sco_sock_clear_timer(sk); > sco_chan_del(sk, err); > release_sock(sk); > - sock_put(sk); > > /* Ensure no more work items will run before freeing conn. */ > cancel_delayed_work_sync(&conn->timeout_work); > + sock_put(sk); Hi Hillf, Saw that this passed the reproducer. But on closer inspection, I think what's happening is that sco_conn_del is never run. So the extra sock_hold prevents a UAF, but that's because now the reference count never goes to 0. In my opinion, something closer to your previous proposal (+ also addressing other calls to __sco_sock_close) where we call cancel_delayed_work_sync after the channel is deleted would address the root cause better. Just my two cents. > } > > hcon->sco_data = NULL; > @@ -212,6 +211,8 @@ static void __sco_chan_add(struct sco_co > > sco_pi(sk)->conn = conn; > conn->sk = sk; > + /* make timeout_work safe; will be put in sco_conn_del() */ > + sock_hold(sk); > > INIT_DELAYED_WORK(&conn->timeout_work, sco_sock_timeout); > > -- >