Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3469075ioo; Mon, 30 May 2022 02:47:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3O4kgXJsPMz56w7nbIC5gQNGO8bedn4iv0R7LlLfmnp+5JSM1oeYmrMAj9JVx5ealzGEU X-Received: by 2002:a05:6402:2712:b0:42b:476b:6c71 with SMTP id y18-20020a056402271200b0042b476b6c71mr45480467edd.413.1653904019965; Mon, 30 May 2022 02:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653904019; cv=none; d=google.com; s=arc-20160816; b=Ll+hbnYQBKg8uLaqBb3FEwtnEmZ9xKz0Rp0FxqeMjHCHDwA6/vql1H6VBW3doaONW0 BNDobeavWkRB71YhkNdu8LmH8V5y1RRMRy/rBMdD6xZdLbO1qUMGJfyDH0EDQjf044wc W2t9fgWwA/1CHyUWRzseXXpkALsvF2U0bi394EnOGejv6342TufQRXSTx6KNCmtgXlJK 40shNTPkj8zGhpjZRkwywYAzyYY14Oa7uaT4Du2/zdAFsjLaTLCidxpJeo/FiyRTwcN/ ByViLKi4xW9a3j5KexsKdHodQBQynE3RB7QVhaCChwqZo9c8gHbjTArLg7mCjV6vHaIh +eiA== 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=8yONYlrK0m7t62BuxO66drXe6hDffZ/aIBXWwETDiX8=; b=xSqUcjegpBougEY8LvjeHTJRzZ8zELso/Zx7DXbzjC1Ub/9APK8x4dNOEuyLllKirc KBhOt7DDo27eeX/OEbpVdH3ilqoU6EfDaULOSYtB5TcnjT7xOfJgciHn24L103tZvhO0 T0GmV0MGnJ8E7mgRPApOKGvt0Iwx6FOoDuygbRanb+6nd1hpfPmP8Y+5WRQt43pbJu2z OpYk2p1PEYvbqVOXnZvcN4e4EkYDtDhMmhCQhaNgzdHv0Z4YixVl8ij3SHanyYhIiSRa 0Q13FcE4tb7KrqadEK2CuSy7avcVwRCx+l15ooF/aEPKkdMNTKlSSqjPIodN6F5q7car AjFQ== 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 m20-20020a056402511400b00425ebf85fe4si9496481edd.558.2022.05.30.02.46.19; Mon, 30 May 2022 02:46:59 -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 S233223AbiE3IND (ORCPT + 99 others); Mon, 30 May 2022 04:13:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233367AbiE3INA (ORCPT ); Mon, 30 May 2022 04:13:00 -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 1BF3764705 for ; Mon, 30 May 2022 01:12:54 -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-644-GIYGgpYFMjSzz1YaLsDptg-1; Mon, 30 May 2022 04:12:48 -0400 X-MC-Unique: GIYGgpYFMjSzz1YaLsDptg-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 1CD3129AB45B; Mon, 30 May 2022 08:12:48 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.64.242.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id D32D31410F36; Mon, 30 May 2022 08:12:45 +0000 (UTC) From: Gopal Tiwari To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, gtiwari@redhat.com Subject: [Bluez 10/13] Fixing use after free in src/device.c Date: Mon, 30 May 2022 13:42:06 +0530 Message-Id: <20220530081209.560465-11-gopalkrishna.tiwari@gmail.com> In-Reply-To: <20220530081209.560465-1-gopalkrishna.tiwari@gmail.com> References: <20220530081209.560465-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