Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp967785rdb; Fri, 9 Feb 2024 06:39:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGY1R5HfViUWaEwBavyDCil4DQuYqMx4pJIgqgP3M36lSMv8xNUrlkopeyBoPM52so8YXgB X-Received: by 2002:a17:90b:3781:b0:297:12da:505d with SMTP id mz1-20020a17090b378100b0029712da505dmr412444pjb.8.1707489589046; Fri, 09 Feb 2024 06:39:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707489589; cv=pass; d=google.com; s=arc-20160816; b=RKxLuEoVPp0mMI4FsFuZquHPoP1czRCnXxxHTWuNQVnsvFvitJsUrtMba4e7zTy7rr wHnMHYi9Yx/SEYTid3KvUKO7KevQ/Tn8ZeYH/4EavJbUCHvcqG0AQpUBHcQlpXewyhWB gsoUTMgWnWD3bRoUwd40wkVm0EeEOtkkWhBVpIdVsDrdaau7NhPAp37wzsapnoaDPvw6 OBAu8Oy/ok+gnPcBSdqygf3DnBi4O9NF2Qwqua2HNFNPkvhRLwxolTeve+Ry421lcH7u utCZifZFPvLEl6D4GLvrKVoyRHPFdAvaAwqVDuqFHschmhwR6L4RiYs9Soy4hqsAEX58 kjMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=y2q5FAm9/EenLzzRVkbIiynIYd7YyHOUHU8wwmN+aQI=; fh=kjwA/ajnqkI2OZh5slbwrN9UKuboQwF32GKyuGI8Fsk=; b=cSnVpzbB5aNcEJi081gjNfUVFbKJDM91NuFfCUd4o67TrXh5wGtRwy5rXMFInkaZxo uHfzvAQJ2SacKFFOztcrkmqCUn112y/CvWLPLAN0SMu6SKwjty7Iu2RyelpFfSR1CocX o4wm2uVFQFe7oodVCfReEvq1s16oS8Cls5tmoFFw+ojecuEM1zxCI7v8f7H/fhXVDShg s7DYqyyu33PJhAeYiU1MEjZtRw16GTaNGjCUIimOoCj555Gd0Y1jN5R1CyTtRWJ7EYP0 lH6AWTw7qVY7+TQh2tBX9X9holhZoD1ekqmqs8aN9BBK4IZTpDZbPX9RzHBeDLHAkGSL UcuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dQJdh4j5; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-1711-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1711-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCXpIEvgZlna429d5r3O53TBBuMZc3UztIwviywarLLtRHwghENPXDYXTnNd5efq0swTRGVJKeAyc7AOVIJ96GlL6ia6/yd4SpryJYdvwA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u27-20020a63b55b000000b005dbf27229f6si1813704pgo.343.2024.02.09.06.39.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 06:39:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-1711-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dQJdh4j5; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-1711-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1711-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8A47B285058 for ; Fri, 9 Feb 2024 14:39:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CAEC56F07C; Fri, 9 Feb 2024 14:37:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dQJdh4j5" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 499A96EB4A; Fri, 9 Feb 2024 14:37:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707489469; cv=none; b=p1NyQXwNTZ6KqtVY282gQ3TrN+w7hXqwgtWFgtFvUIzzkYo+3oJlVk5chLLvNiQKh1eoukk44JItCTxCG9tu9QwaJBKTq5ZjJuQpNuK0dtcyiNBXuwAFkseKexrkMsNizVGPF5O/jJT0aA+sNTVPDyeE3vDnNrsxEMyjSs6/ock= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707489469; c=relaxed/simple; bh=8yJ/tmDXR4RZPdenfUZjzryKPR24G4VB9nfSLxysEYM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Ropz4PYIm6hR8opQA0V0/EGG/JKrBZr/YIktMAcbxhJ2iM/+WRoPxUGsfiq1r4E6qqZUacEE20GWcmkB56l7cAnkb7exQh88kPXtEdZwy81svlAW0lltkkzpijSu3Btpjc0jml4f8+gDnteBEbF5HKtqoK6FLF6bsclrX/9E74s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dQJdh4j5; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d066b532f0so14429341fa.1; Fri, 09 Feb 2024 06:37:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707489465; x=1708094265; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=y2q5FAm9/EenLzzRVkbIiynIYd7YyHOUHU8wwmN+aQI=; b=dQJdh4j5Dwjd24z22HQ4go/EfjXa9dbA2CbaSfJENO0CkNvnN7/kkGjI1BUZeIr0Zf FFuofUV92NqGaas5ujnia8OrYL5un6muAKNQgn3LwT+ClxeoM7v545cG11yYey7Ebzo0 6JJg1sizSxrByvLcbAIbYKEF6La9shUQGeXoS3/WZ+GZ7o28hdoOLGMlXmt5e72oAHNZ egTj4wGa1GzK5TN6u4hWTKMHAgFnD1WxhkCy3PP/4LXSwmH1Myyv42lJbtSFsRRMp8aI a8LMVnXwTqV+Jz9cvaQ8BREkKSz7wV2ZXJVrYJdMmu2I5rJ5pm1/wRv+2Mx4JIKBu9Jy GTdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707489465; x=1708094265; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y2q5FAm9/EenLzzRVkbIiynIYd7YyHOUHU8wwmN+aQI=; b=qVddDch+3ExF+dPEVuheID1duzbuKQ2PWnLu4wL3IHnIEXXgAtLDziy9fpSA2wpEBe 0aoJgvP43/plUyydR6mV469ze4nal1eHekVmLB1cQByCHOzsWY1S92+0HWoGVFBZTFs3 rqhacSCgWxiCQMHKDCjwvLHkLUt3K8ovGwKgX+IA8DC3nxeQiv7mkcQfOyfHajl7XLSa J117QflbQqWAtXhCgoBfOiuAW/kW3egaF5RodX00LRNRFe05oXrxAqgJ6uKrbB82zl80 EAxM/qKDeUBWf/6fm6UWYQiuKir9crS96zOY0DXW6BkVQsoGgo6aDB7TCqsrXYjSOMHh hm/g== X-Gm-Message-State: AOJu0YwfrRKCY0rqCLT8rBC2RqaPQqWOBif0wvzmTIw3zl19qozi/IEX MpTarFhZWFc/QwQ8YObdZSy4uwQPuKcO09mynR5n1/Kl+YhfPu/RPTradrD/q8nxOToI63LD0qn lDM5J3Fj+rKb+tYC0h0IlB4SAtQM= X-Received: by 2002:a2e:a4c6:0:b0:2d0:b750:514c with SMTP id p6-20020a2ea4c6000000b002d0b750514cmr1484382ljm.9.1707489465133; Fri, 09 Feb 2024 06:37:45 -0800 (PST) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <0000000000007cea730610e083e8@google.com> <216c95d9-db1f-487a-bf3d-17a496422485@v0yd.nl> In-Reply-To: From: Luiz Augusto von Dentz Date: Fri, 9 Feb 2024 09:37:32 -0500 Message-ID: Subject: Re: [syzbot] [bluetooth?] KASAN: slab-use-after-free Write in __hci_acl_create_connection_sync To: =?UTF-8?Q?Jonas_Dre=C3=9Fler?= Cc: syzbot , davem@davemloft.net, edumazet@google.com, johan.hedberg@gmail.com, kuba@kernel.org, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, luiz.von.dentz@intel.com, marcel@holtmann.org, netdev@vger.kernel.org, pabeni@redhat.com, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Jonas, On Fri, Feb 9, 2024 at 8:36=E2=80=AFAM Luiz Augusto von Dentz wrote: > > Hi Jonas, > > On Fri, Feb 9, 2024 at 7:37=E2=80=AFAM Jonas Dre=C3=9Fler wrote: > > > > Hi everyone! > > > > On 08.02.24 16:32, syzbot wrote: > > > syzbot has bisected this issue to: > > > > > > commit 456561ba8e495e9320c1f304bf1cd3d1043cbe7b > > > Author: Jonas Dre=C3=9Fler > > > Date: Tue Feb 6 11:08:13 2024 +0000 > > > > > > Bluetooth: hci_conn: Only do ACL connections sequentially > > > > > > bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=3D154f85= 50180000 > > > start commit: b1d3a0e70c38 Add linux-next specific files for 202402= 08 > > > git tree: linux-next > > > final oops: https://syzkaller.appspot.com/x/report.txt?x=3D174f85= 50180000 > > > console output: https://syzkaller.appspot.com/x/log.txt?x=3D134f85501= 80000 > > > kernel config: https://syzkaller.appspot.com/x/.config?x=3Dbb693ba19= 5662a06 > > > dashboard link: https://syzkaller.appspot.com/bug?extid=3D3f0a39be7a2= 035700868 > > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=3D11d9514= 7e80000 > > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=3D107c2d8fe= 80000 > > > > > > Reported-by: syzbot+3f0a39be7a2035700868@syzkaller.appspotmail.com > > > Fixes: 456561ba8e49 ("Bluetooth: hci_conn: Only do ACL connections se= quentially") > > > > > > For information about bisection process see: https://goo.gl/tpsmEJ#bi= section > > > > Hmm, looking at the backtraces, I think the issue that the introduction= of the > > sequential connect has introduced another async case: In hci_connect_ac= l(), when > > we call hci_acl_create_connection_sync(), the conn state no longer imme= diately > > gets set to BT_CONNECT, but remains in BT_OPEN or BT_CLOSED until the h= ci_sync > > queue actually executes __hci_acl_create_connection_sync(). > > Need to double check but I think we do set BT_CONNECT in case of LE > when it is queued so which shall prevent it to be queued multiple > times. > > > This means that now hci_connect_acl() is happy to do multiple > > hci_acl_create_connection_sync calls, and the hci_sync machinery will h= appily > > execute them right after each other. Then the newly introduced hci_abor= t_conn_sync() > > in __hci_acl_create_connection_sync() calls hci_conn_del() and frees th= e conn > > object, so the second time we enter __hci_acl_create_connection_sync(), > > things blow up. > > > > It looks to me like in theory the hci_connect_le_sync() logic is prone = to a > > similar issue, but in practice that's prohibited because in hci_connect= _le_sync() > > we lookup whether the conn object still exists and bail out if it doesn= 't. > > > > Even for LE though I think we can queue multiple hci_connect_le_sync() = calls > > and those will happily send HCI_OP_LE_CREATE_CONN no matter what the co= nnection > > state actually is? > > > > So assuming this analysis is correct, what do we do to fix this? It see= ms to me > > that > > > > 1) we want a BT_CONNECT_QUEUED state for connections, so that the state > > machine covers this additional stage that we have for ACL and LE connec= tions now. > > BT_CONNECT already indicates that connection procedure is in progress. > > > 2) the conn object can still disappear while the __hci_acl_create_conne= ction_sync() > > is queued, so we need something like the "if conn doesn't exist anymore= , bail out" > > check from hci_connect_le_sync() in __hci_acl_create_connection_sync(),= too. > > Btw, I'd probably clean up the connect function and create something > like hci_connect/hci_connect_sync which takes care of the details > internally like it was done to abort. > > > That said, the current check in hci_connect_le_sync() that's using the = connection > > handle to lookup the conn does not seem great, aren't these handles re-= used > > after connections are torn down? > > Well we could perhaps do a lookup by pointer to see if the connection > hasn't been removed in the meantime, that said to force a clash on the > handles it need to happen in between abort, which frees the handle, > and connect, anyway the real culprit here is that we should be able to > abort the cmd_sync callback like we do in LE: > > https://github.com/bluez/bluetooth-next/blob/master/net/bluetooth/hci_con= n.c#L2943 > > That way we stop the connect callback to run and don't have to worry > about handle re-use. https://patchwork.kernel.org/project/bluetooth/patch/20240209141612.3554051= -1-luiz.dentz@gmail.com/ > > > Cheers, > > Jonas > > > > -- > Luiz Augusto von Dentz --=20 Luiz Augusto von Dentz