Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2684223rwb; Thu, 29 Sep 2022 13:35:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6nBFZY93fhoVwCtSIsDRMfr1+a/8V9lJUhcmnkimkYVdjmAWhyres6fkYXyT5GcsdrHpud X-Received: by 2002:a05:6402:168c:b0:458:5b8b:afd2 with SMTP id a12-20020a056402168c00b004585b8bafd2mr2178059edv.357.1664483756208; Thu, 29 Sep 2022 13:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664483756; cv=none; d=google.com; s=arc-20160816; b=PbX+WC9NBCWe7mhbtA17952cXEGp+9VHF4U9BXYIPD0bJUnSMsgdH0Wyh5leBB8+YA DpEAB8p7kwHSDzQEzPb3zrnOD2VOKA28D3HH32PwZkdUv/pd+hhxbXh7NvYwRWi0VbKb PKB7KC5pvOw8Sy+Nodd/3QeHovuSdaq3+GHgVWLmwxfBuXsGj8XbjJVpbtou666ux8vk eVEo4NfgV/61T96f2IJn3TlELyK+KUe1Mui6lJ7BOURZ6eE+qwzpoTPplue67zKyl5kL gxigJKZyl0ISBHzipzGZSF49hC5T6pYlLctkD5hcVAj1QYA2kfJ3BAwLR9+panwKf7Ne Gi+A== 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=FeeOZAtAjZUmYD55G5V8TWYnHZX+4Y4ahas6G0qZxSI=; b=rcU0qU0CKhiSdUy7ccpEDTDJD0vLGUVJptjc1n7OLvrLdvEoz3b0XyY8kiNDgCrkgc Azgp9lmb4Kk45WWnWsJQa5imqQbO8k6VowPVl6x4jVDIFu2gBhCHQsh7Tpf1Ibqymy3Y g0OCNPr+tu1NxNbaga2369ExiIbrrFXr4w7dBXobuvIp8agMcBGiHXVGzGo3j1qECwW+ wzct41ZjZHMydLJeQVFeUPalbt/fBcL7jEYOm576pU+77ydpnUL4y9Cj6UbwJJ62HYAP 7mH0EXc8sDPD8P/VAUfmFUFN7CGDFgYhDwaeDJOCfq/jDjPMItdyGu7C2l5SuQKnyrqk KHDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jlLfVacV; 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 x10-20020a50ba8a000000b004571d72417fsi378729ede.308.2022.09.29.13.35.25; Thu, 29 Sep 2022 13:35:56 -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=jlLfVacV; 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 S229633AbiI2Ucq (ORCPT + 99 others); Thu, 29 Sep 2022 16:32:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbiI2Uco (ORCPT ); Thu, 29 Sep 2022 16:32:44 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E38612968F for ; Thu, 29 Sep 2022 13:32:44 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id g1-20020a17090a708100b00203c1c66ae3so2423498pjk.2 for ; Thu, 29 Sep 2022 13:32:44 -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:subject:date; bh=FeeOZAtAjZUmYD55G5V8TWYnHZX+4Y4ahas6G0qZxSI=; b=jlLfVacVCDrYd1X4HjtG3kSMpr+CxJ1FA9PzrXYXLJFi5Sj2bjERdr/MCH3bLsfyAD DORdtMEVpEdDVDeP77Pz6CuFq6o4e5h8GLmoKKE6DHu+f6ofvkiQ04di5bNU43KFmT2D mXItV56kJ1i+mpPg1PdHUtdqec645DaBJmoX+r0rwlxZJRgV2pAqrjU+eRUY5slZrK2d aEBCN6R+XufJm9WJ689HhtMRD/1x04d0x/IRPEp366xXJMc97S5D5yDzd7AmoMaunilk kmBFP/YGZNE75KoMO9SqfwwDYAdIcc1QyxQvvEZsvTqexuP/Sm0yrpkbfeCtyHKoMslJ +ulg== 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:subject:date; bh=FeeOZAtAjZUmYD55G5V8TWYnHZX+4Y4ahas6G0qZxSI=; b=4ltU15bgQPm+OtTJilugI+md5nzwl1R57ePvgopOSgtjFLAjZHWVQfEpsni6dz7uHX ZWmfzac/U8m09B8Wj2HUIeS3ZO6kbmX2vNnB8Jnrz6dD/QkMvqXxqW8b729zIhhnJHAM tbXSaa7uDIqZ4ngWWxrRg2FUoDTzmJbIlAIRCI02me+eN79E9X3RH/unBUJkLeEDgTDA lF4LGcZJ7XC/Ijqt3siYEKZTf4lDLlCXoYl3oQnZ3EbOcgTw/c++KkC5JIVca0m8ic94 joQHgGGWRIPQScwXs9QG7XKHWyhcr5TLkPxTehzGrUW6fM5vRR8DGKQ1hq2W9P4NBZdT ZSCw== X-Gm-Message-State: ACrzQf2m4S3/JXVBHryTdjfGuekqrzt+f8D9eD0Q9c9REZS7GLltBaxu hBP8fRyCy/z9s5bbKcIpalH5/6ZQE7o= X-Received: by 2002:a17:903:22d0:b0:177:e5b2:c598 with SMTP id y16-20020a17090322d000b00177e5b2c598mr5230030plg.56.1664483562995; Thu, 29 Sep 2022 13:32:42 -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 t131-20020a635f89000000b004393c5a8006sm298451pgb.75.2022.09.29.13.32.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 13:32:42 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH] Bluetooth: L2CAP: Fix user-after-free Date: Thu, 29 Sep 2022 13:32:41 -0700 Message-Id: <20220929203241.4140795-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 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 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 This uses l2cap_chan_hold_unless_zero() after calling __l2cap_get_chan_blah() to prevent the following trace: Bluetooth: l2cap_core.c:static void l2cap_chan_destroy(struct kref *kref) Bluetooth: chan 0000000023c4974d Bluetooth: parent 00000000ae861c08 ================================================================== BUG: KASAN: use-after-free in __mutex_waiter_is_first kernel/locking/mutex.c:191 [inline] BUG: KASAN: use-after-free in __mutex_lock_common kernel/locking/mutex.c:671 [inline] BUG: KASAN: use-after-free in __mutex_lock+0x278/0x400 kernel/locking/mutex.c:729 Read of size 8 at addr ffff888006a49b08 by task kworker/u3:2/389 Link: https://lore.kernel.org/lkml/20220622082716.478486-1-lee.jones@linaro.org Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sungwoo Kim --- net/bluetooth/l2cap_core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 770891f68703..1f34b82ca0ec 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4309,6 +4309,12 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, } } + chan = l2cap_chan_hold_unless_zero(chan); + if (!chan) { + err = -EBADSLT; + goto unlock; + } + err = 0; l2cap_chan_lock(chan); @@ -4338,6 +4344,7 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, } l2cap_chan_unlock(chan); + l2cap_chan_put(chan); unlock: mutex_unlock(&conn->chan_lock); -- 2.37.3