Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp4654305ioo; Tue, 31 May 2022 08:47:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7tX+QH7FAqg3O7tSigzF7pu9wBtzZ8tedUpcC0muiizkHGS2X0/3i4rX7L9gIjUT+p9Ii X-Received: by 2002:a17:90a:468d:b0:1df:39da:322b with SMTP id z13-20020a17090a468d00b001df39da322bmr29154355pjf.137.1654012041376; Tue, 31 May 2022 08:47:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654012041; cv=none; d=google.com; s=arc-20160816; b=cMuFdGe4sNc7WnhTkwYuMwZdvmcY2New28UaxSDLu4txlkYC8mwHRVeO+SbwBFBzmA hqgTcfwhSqTgHtFfL0ManiOad+m0dkQNmcTq8G0xSgsc2Cb7SlDmr3hFZnwrUfcH6R8x lzWS9InxMOcOErRaFueFTxec6/KzIyvq8Oz3ixx6xqtdb+IpfxLlShkdug06Jcl/enzh PMJoWD/V0iOax/UPFyyTbYlj+gLrAstcRdEO3NKMLk/wWOXRIwEEqnXJPjOmwq7+cKc6 GJq5NxpFkRhO1ogQ8PocpEOlLjsdhC5NxAF/GEV//+zTMnJs0HKwatLMM4Ht2EmGFmA3 DZ7w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=021bT20LzVgtPHUGMUR8HL3BljuXfy5UuvHRdGI1Evs=; b=FmbHj31fy3CuruPhkX54me7/2p4e/jDoD2w6OB6Qi822rlQUKfimpQATxSXvPPFfMs rTjaIeifSRdpWz3Qdg1R9aFmYw77avTm2FxKtd1P9tLbGtXmYzP5ixS7sHpGskz0BzU0 KSerc7uLDutZVyfAg/14HjdZ7HsTpf+bd8s3JWHL5QzFDJhBzvzCXWOozKTPa0J3lSfa cvaPVWcKxCmxG71xJn7CHGuw6UEWOORJAEK4z8EDTXjPJhP5+MsD1kVfulEIYREyg1UE i39cSddCSInUId/YdgtnsLGeumdtbRW4UKtvbJpvdZ3DM02h8yewOnUV2c4rPdYBd30N srlw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 75-20020a63004e000000b003fc2c0d5780si6191535pga.298.2022.05.31.08.46.51; Tue, 31 May 2022 08:47:21 -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; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242843AbiEaHmL (ORCPT + 99 others); Tue, 31 May 2022 03:42:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244588AbiEaHmD (ORCPT ); Tue, 31 May 2022 03:42:03 -0400 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 193C417054 for ; Tue, 31 May 2022 00:41:59 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-502-SoPxMpqFPm-69KalcedRPQ-1; Tue, 31 May 2022 03:41:56 -0400 X-MC-Unique: SoPxMpqFPm-69KalcedRPQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4C5A33C138A8; Tue, 31 May 2022 07:41:56 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.64.242.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A75F1415100; Tue, 31 May 2022 07:41:53 +0000 (UTC) From: Gopal Tiwari To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, gtiwari@redhat.com Subject: [Bluez V2 10/13] Fixing use after free in src/device.c Date: Tue, 31 May 2022 13:11:14 +0530 Message-Id: <20220531074117.610321-11-gopalkrishna.tiwari@gmail.com> In-Reply-To: <20220531074117.610321-1-gopalkrishna.tiwari@gmail.com> References: <20220531074117.610321-1-gopalkrishna.tiwari@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no 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: Gopal Tiwari Following traces reported by covirty tool Error: USE_AFTER_FREE (CWE-416): bluez-5.64/src/device.c:2962: path: Condition "!dbus_message_get_args(msg, NULL, 0 /* (int)0 */)", taking false branch. bluez-5.64/src/device.c:2965: path: Condition "device->bonding", taking false branch. bluez-5.64/src/device.c:2968: path: Condition "device->bredr_state.bonded", taking true branch. bluez-5.64/src/device.c:2969: path: Falling through to end of if statement. bluez-5.64/src/device.c:2977: path: Condition "state->bonded", taking false branch. bluez-5.64/src/device.c:2983: path: Condition "agent", taking true branch. bluez-5.64/src/device.c:2984: path: Falling through to end of if statement. bluez-5.64/src/device.c:2990: path: Condition "agent", taking true branch. bluez-5.64/src/device.c:3005: path: Condition "bdaddr_type != 0", taking true branch. bluez-5.64/src/device.c:3006: path: Condition "!state->connected", taking true branch. bluez-5.64/src/device.c:3006: path: Condition "btd_le_connect_before_pairing()", taking true branch. bluez-5.64/src/device.c:3007: freed_arg: "device_connect_le" frees "device->bonding". bluez-5.64/src/device.c:3007: path: Falling through to end of if statement. bluez-5.64/src/device.c:3012: path: Falling through to end of if statement. bluez-5.64/src/device.c:3017: path: Condition "err < 0", taking true branch. bluez-5.64/src/device.c:3018: double_free: Calling "bonding_request_free" frees pointer "device->bonding" which has already been freed. Signed-off-by: Gopal Tiwari --- src/device.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/device.c b/src/device.c index 8dc12d026..a0e5d40db 100644 --- a/src/device.c +++ b/src/device.c @@ -2942,6 +2942,7 @@ static void bonding_request_free(struct bonding_req *bonding) bonding->device->bonding = NULL; g_free(bonding); + bonding = NULL; } static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg, -- 2.26.2