Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1086489imi; Fri, 1 Jul 2022 02:48:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tNqkJOtBTQJSOVY53/BQ+tQ5zBY9pinAj1K5AdQz3fhkEwW5IoBsTJMlF5fU7zyNUwSO9U X-Received: by 2002:a17:906:b795:b0:722:e662:cffe with SMTP id dt21-20020a170906b79500b00722e662cffemr13628549ejb.121.1656668930577; Fri, 01 Jul 2022 02:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656668930; cv=none; d=google.com; s=arc-20160816; b=cDeduPsKkK+JkQA9Zxjy10P4/44byFoLGY+qp/EfOJNEeY0/8hFtXsZUuhgpk503xF ecjm3Tz0a5OpCHZeKdpIv9f2ex28l5yFk/yoT/kzKJ8/ZDEogAgE5BnMahycosoemjB7 lrO/pETw1J5vYoYAw4Iz3Gx128EcH3qfvH8j2oYfxo7zfb4Ede5NJ7EwUvlzMyRNhwOc 1vpVmoGyKVSYcd6S5Sd9f9tfS+g7XvvvuJkNx4ey4bUsmlbeYI/1nL3l3GRYKDtiyBY9 G+sRBjq1s5FOrrrhmoFTNRphWhUIiQ3CSFiyA2WWvCQ635Yz3SfnUUnCpLnoWXSp+ofX Rl6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=BTdWQRQrroB5qKlY/CmNun+Ie1cNvx1/cFuksR740cg=; b=r94xovBfJOnpiQu1z1NGSmSMVA/v5iLRKSP2243sP4Y8GVapcZhUJ+4xaykIGkNvBA EW8v4OyUVLg7W0zpxjt7GC+u21Y6PqseEakrC0AQO37dcplKbEbO0rnp9v6BtG7xbshP teHVLqSwa9dMg+P3TqXa9c5kboRH4CH9i/yhBNO5T7HjnAvREi1zKayu8er97qTFk6JI 1Ox/9/Cvj2wVFaWVw6xl9VJRCqfZMywJxe1btxez5TwkK6S5XnYTywsciP/0ixBMbAb8 2SpG/m3swwHsWnsrwFbR3ErFcfprqtnxwmKcIhWmi5n0wzEzZF8E1dAhzij6Xsw0WpEY gk9g== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fj4-20020a1709069c8400b00711d50b288fsi995101ejc.547.2022.07.01.02.48.13; Fri, 01 Jul 2022 02:48:50 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236051AbiGAJlR (ORCPT + 99 others); Fri, 1 Jul 2022 05:41:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233785AbiGAJlR (ORCPT ); Fri, 1 Jul 2022 05:41:17 -0400 Received: from smtpbguseast1.qq.com (smtpbguseast1.qq.com [54.204.34.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B94E30F67 for ; Fri, 1 Jul 2022 02:41:14 -0700 (PDT) X-QQ-mid: bizesmtp70t1656668468t4mk9fk8 Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 01 Jul 2022 17:41:04 +0800 (CST) X-QQ-SSF: 01400000002000C0E000000A0000000 X-QQ-FEAT: GPA+zXMP6Q6t47N44j56+XKmpvDOOHWo59hxiXlc3FPK4Vzgq824TcJQ2D+N3 6i0QBcXIJGJQJ/AWEuojMkD0KLNZ8hvuU/9ZudLQlXRmiftgLDFtTzKweqGRi9SLAUMrbv6 Tnx4+4L2u68P0fM3siPkPaNdSayqXqV+NbglrOoowLOqwYClAgFRh6O/xIR7D3er05iNyju xDwhjE07UM6fEmFZvL16PDZb/Up9Y8L47YK8L9294qIoemUYNLvdF8+eWwk6FW5F5s9OYEe t1QQpJBEPjGOeoyS9DE3F4Oj29EqskrZVQb2ZWVvMeKMb8tvcWep/Viz81Z+pRfReZjLH/x pwPw7ViNxC3DT1Pe0KIPlRG7O2UZRU8PZn5F3Mf X-QQ-GoodBg: 1 From: Youwan Wang To: linux-bluetooth@vger.kernel.org Cc: Youwan Wang Subject: [PATCH] obexd: fix crashed after cancel the on-going transfer Date: Fri, 1 Jul 2022 17:41:02 +0800 Message-Id: <20220701094102.25917-1-wangyouwan@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign9 X-QQ-Bgrelay: 1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 There is a use after released.transfer->req_id different obex->pending_req->id,See the following log, The packages is removd in cancel_complete func are not the same package in req_timeout func, but transfer pointer is released. log: g_obex_cancel_req() transfer->req_id 23 id 22 obex->pending_req(0x55b642c3e100) g_obex_cancel_req() match->data (0x55b642c344a0) g_obex_ref() ref 4 cancel_complete() pending req timeout 176 id 22 obex(0x55b642c3e100) transfer_response() obex 0x55b642c36480 transfer(0x55b642c3d000) g_obex_drop_tx_queue() g_obex_unref() obex 0x55b642c36480 g_obex_unref() ref 3 transfer_free() obex 0x55b642c36480 transfer 0x55b642c3d000 g_obex_unref() obex 0x55b642c36480 g_obex_unref() ref 2 pending_pkt_free() timeout_id 0 pending_pkt (0x55b642c344a0) step: [obex]# connect 28:33:34:1E:96:98 Attempting to connect to 28:33:34:1E:96:98 [NEW] Session /org/bluez/obex/client/session2 [default] [NEW] ObjectPush /org/bluez/obex/client/session2 Connection successful [28:33:34:1E:96:98]# send /home/uos/Desktop/systemd.zip Attempting to send /home/uos/Desktop/systemd.zip [NEW] Transfer /org/bluez/obex/client/session2/transfer2 Transfer /org/bluez/obex/client/session2/transfer2 Status: queued Name: systemd.zip Size: 33466053 Filename: /home/uos/Desktop/systemd.zip Session: /org/bluez/obex/client/session2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 [CHG] Transfer /org/bluez/obex/client/session2/transfer2 er2 33:34:1E:96:98]# cancel /org/bluez/obex/client/sessi Attempting to cancel transfer /org/bluez/obex/client/s Cancel successful valgrind trace: ==11431== Invalid read of size 4 ==11431== at 0x12B442: transfer_response () ==11431== by 0x127764: req_timeout () ==11431== by 0x49B8922: ??? ( ) ==11431== by 0x49B7E97: g_main_context_dispatch () ==11431== by 0x49B8287: ??? (in ) ==11431== by 0x49B8581: g_main_loop_run () ==11431== by 0x121834: main (main.c:322) ==11431== Address 0x7344fa0 is 16 bytes inside a block of size ==11431== at 0x48369AB: free () ==11431== by 0x12B459: transfer_response () ==11431== by 0x127B3D: cancel_complete () ==11431== by 0x49B7E97: g_main_context_dispatch () ==11431== by 0x49B8287: ??? () ==11431== by 0x49B8581: g_main_loop_run () ==11431== by 0x121834: main (main.c:322) ==11431== Block was alloc'd at ==11431== at 0x4837B65: calloc () ==11431== by 0x49BD9D8: g_malloc0 () ==11431== by 0x12AB89: transfer_new () ==11431== by 0x12B732: g_obex_put_req_pkt () ==11431== by 0x12B732: g_obex_put_req_pkt () ==11431== by 0x146982: transfer_start_put () ==11431== by 0x146982: obc_transfer_start () ==11431== by 0x13C5A7: session_process_transfer () ==11431== by 0x13D248: session_process_queue () ==11431== by 0x13D248: session_process_queue () ==11431== by 0x13D2AF: session_process () ==11431== by 0x49B7E97: g_main_context_dispatch () ==11431== by 0x49B8287: ??? (i) ==11431== by 0x49B8581: g_main_loop_run () ==11431== by 0x121834: main () ==11431== ==11431== (action on error) vgdb me ... --- gobex/gobex-transfer.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c index c94d018b2..2b6b0321d 100644 --- a/gobex/gobex-transfer.c +++ b/gobex/gobex-transfer.c @@ -83,15 +83,20 @@ static struct transfer *find_transfer(guint id) static void transfer_complete(struct transfer *transfer, GError *err) { - guint id = transfer->id; + guint id; - g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", id); + if (!g_slist_find(transfers, transfer)) + return; + + transfer->req_id = 0; + g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id); if (err) { /* No further tx must be performed */ g_obex_drop_tx_queue(transfer->obex); } + id = transfer->id; transfer->complete_func(transfer->obex, err, transfer->user_data); /* Check if the complete_func removed the transfer */ if (find_transfer(id) == NULL) @@ -107,8 +112,6 @@ static void transfer_abort_response(GObex *obex, GError *err, GObexPacket *rsp, g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id); - transfer->req_id = 0; - /* Intentionally override error */ err = g_error_new(G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED, "Operation was aborted"); @@ -184,12 +187,6 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp, struct transfer *transfer = user_data; GObexPacket *req; gboolean rspcode, final; - guint id; - - g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id); - - id = transfer->req_id; - transfer->req_id = 0; if (err != NULL) { transfer_complete(transfer, err); @@ -203,6 +200,9 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp, goto failed; } + if (!g_slist_find(transfers, transfer)) + return; + if (transfer->opcode == G_OBEX_OP_GET) { handle_get_body(transfer, rsp, &err); if (err != NULL) @@ -222,8 +222,6 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp, req = g_obex_packet_new(transfer->opcode, TRUE, G_OBEX_HDR_INVALID); } else { - /* Keep id since request still outstanting */ - transfer->req_id = id; return; } -- 2.20.1