Linux bluetooth development
 help / color / mirror / Atom feed
From: Rahul Samana <rahul.samana@oss.qualcomm.com>
To: linux-bluetooth@vger.kernel.org
Cc: quic_mohamull@quicinc.com, quic_hbandi@quicinc.com,
	quic_anubhavg@quicinc.com,
	Rahul Samana <rahul.samana@oss.qualcomm.com>
Subject: [PATCH v1] gobex: Fix use-after-free when cancelling SRM PUT transfer
Date: Tue,  7 Jul 2026 12:05:43 +0530	[thread overview]
Message-ID: <20260707063543.80320-1-rahul.samana@oss.qualcomm.com> (raw)

In SRM mode put_get_data() queues the next packet during encoding of
the current one, so transfer->req_id and pending_req->id can diverge.
When g_obex_cancel_transfer() cancels the queued packet from tx_queue,
cancel_complete() frees the transfer while pending_req still holds a
callback pointing to it. Its G_OBEX_DEFAULT_TIMEOUT (10s) then fires
on freed memory causing a SIGSEGV.

Fix by clearing pending_req->rsp_func if it belongs to the same
transfer being cancelled.

Signed-off-by: Rahul Samana <rahul.samana@oss.qualcomm.com>
---
 gobex/gobex.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/gobex/gobex.c b/gobex/gobex.c
index df80d79f3..10a438391 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -861,6 +861,14 @@ gboolean g_obex_cancel_req(GObex *obex, guint req_id, gboolean remove_callback)
 
 	g_queue_delete_link(obex->tx_queue, match);
 
+	/* In SRM mode pending_req may belong to the same transfer but carry
+	 * a different req_id. Clear its callback to avoid use-after-free
+	 * when its timeout fires after transfer_free().
+	 */
+	if (remove_callback && obex->pending_req &&
+				obex->pending_req->rsp_data == p->rsp_data)
+		obex->pending_req->rsp_func = NULL;
+
 immediate_completion:
 	p->cancelled = TRUE;
 	p->obex = g_obex_ref(obex);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


             reply	other threads:[~2026-07-07  6:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07  6:35 Rahul Samana [this message]
2026-07-07  9:24 ` [v1] gobex: Fix use-after-free when cancelling SRM PUT transfer bluez.test.bot
2026-07-09 15:30 ` [PATCH v1] " patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260707063543.80320-1-rahul.samana@oss.qualcomm.com \
    --to=rahul.samana@oss.qualcomm.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=quic_anubhavg@quicinc.com \
    --cc=quic_hbandi@quicinc.com \
    --cc=quic_mohamull@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox