From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793140774; b=4rjVyV8En2U1caNatiSwy/Te+Pz5JryEs12sfqTTkOGlLBehlmHVyfjSnECOh5flfmSd jijN2wNp9wRElADIy37lqPtQ7CqV6V+LuAc5OBX99yEcZiA8y22/ZbJoOzfXC4bWquTtw e8N4BRs9QgZ9XBkeWA5aEKwv2h/ovWQL/kzry1PSDosQGB09fPRnFavFYMjOW2SNGOiid 8kfihJgA5QasFJvAfdWakFhiGTY5ERi6n/rcHK2cTKSg2mT2HHyJxQ0N/PyHIEP4OMeDw ii+ovMYE8UqU4brna6rIgcII/1p1o6EmDgTCSuVB3v289JP3reVy0d/Fhhuwn/PhE7w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793140774; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=MTMJFM/nqHoym7HFBiG90k6OXEIlh5WHZZg+1coUz9A=; b=3tyqrBJnu4+pYaoWT6NZlcGoptKbewgD18tJDUdEx9cC/6RCsgwyhjwepcy2GN/KAnzt WMNNF7aMlvTiRk9hiA/tUZECEX0h5tLPVhB0eQxCtYAS6t21K4aciIHzsC7kE0bpmG6nE dr2v+CzEvuDhhKK4LjC40VtA7VzweO6We8bxtq5kpNJLa74Hvx3VZSEvQGGwYydkj65y3 hNEv7XfM5rpbUMeCYX0dudsM6Bvoy7Lyh2p0xPOoZNG33LKxiMNa8PfALDifgkdQh/PEr lkwuQfLUELCVz66ngh0dnk80vFao84dnDPORT0Tgx/TTmDRrV9emdSYbbUJu1OQzuJA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=VKg7Sjl8; arc=none smtp.remote-ip=74.125.82.69 Received: from mail-dl1-f69.google.com (mail-dl1-f69.google.com [74.125.82.69]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F60C60A6F5B for ; Tue, 27 Oct 2026 22:39:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9F60C60A6F5B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=VKg7Sjl8 Received: by mail-dl1-f69.google.com with SMTP id a92af1059eb24-19dbbe4b1d8so296858c88.1 for ; Tue, 27 Oct 2026 15:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1793140773; x=1793745573; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=MTMJFM/nqHoym7HFBiG90k6OXEIlh5WHZZg+1coUz9A=; b=VKg7Sjl8mR4pPEGtCoGTGc4UJx8to7fdPZZACtvfuVOf+GkCriltG5TgeE74WC8QQ7 xRmOhP4ZnR/quMVHjH+4hePDakmjmGNp7rpWJKaaCk9R158IXtAzik97bhCgVhA2pakZ q5MntD6Rn9NBv2hAGNrBZwZ47oqt8s4fPyjpgneV7Q6FJ/iXTKskqt4nnRYjlEsFI1rJ P65lbbusojMgwxXpNRcutVom9a1HRPxeMnihQLF4LpplhKxGVPC3CTvps8UZwwFfiI6F LEwWtheoIrtqbrPIX/NtfUJJTuRJicSOloV+cAN/Jnwt51DoTD+wCJPXCelUIT7SGp+U ni+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793140773; x=1793745573; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=MTMJFM/nqHoym7HFBiG90k6OXEIlh5WHZZg+1coUz9A=; b=0vu7l+G9Ch/E5ozphNMGv1ixXxQ0ykHCIjPv99Dtwyf6cDnypeonwo+fsyfs6IK2W+ UalTEG0Jxna0uAKrxoAe2C4yEqGny0RbtJWxVTk+l74TmDZLjDIPVRcHpaFELpiwlHdL 2yiyDsni/lX/tagXagw+vk7uILJr/DAq0Fjq0+Qo2UBjp5p4XYs+KNS3MURFsxyIFJfO rhf56Xa587YO+977FK8KHGIdgDkfKsiE8brRHH3ANEZLbKdMaXWJgg7U+H7hmPUzjvgZ 5bJIzu+NlzVnm1CW+rQNQKZUCl7qerzvLYpxoHgpYx8ZnRCDeuXtOKPpw//o5IFd2/Ks 9eUg== X-Forwarded-Encrypted: i=1; AKwUvBw1butBGZ0gnGga8ki7ON8xq1fQa0imXfGnpWxjiLFhtM61/A9S/vJAVKq9uJtT3A71Ds14ZzzbjSQ/og==@lists.linux.dev X-Gm-Message-State: AFq9FYKG6tvtDul2lSkOH9BrxbOJdLn1Er/2m/GlLPZPJXz+viVomwvH mxadS77qMtKUALwSO1h+YjYQEJKKucRS80QmG0rXqTmZ9nwBzvsut8Xz+rYDc2up6Lg7B1rLp/s /QpZ7XBGUTA== X-Received: from dlea12-n1.prod.google.com ([2002:a05:701b:420c:10b0:1a4:c892:b166]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:701b:2813:b0:143:6525:f9f6 with SMTP id a92af1059eb24-1a6cd3a1575mr630918c88.13.1793140772067; Tue, 27 Oct 2026 15:39:32 -0700 (PDT) Date: Tue, 27 Oct 2026 15:38:43 -0700 In-Reply-To: <20261027223847.652884-1-irogers@google.com> X-Mailing-List: driver-core@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261027223847.652884-1-irogers@google.com> X-Mailer: git-send-email 2.56.0.313.g2479322e68-goog Message-ID: <20261027223847.652884-9-irogers@google.com> Subject: [PATCH v2 8/9] drm/amdkfd: Free queue in procfs_queue_type kobject release callback From: Ian Rogers To: Kees Cook , Greg Kroah-Hartman , Miguel Ojeda , "Rafael J . Wysocki" , Danilo Krummrich Cc: Nathan Chancellor , Nick Desaulniers , Miguel Ojeda , "=?UTF-8?q?Christian=20K=C3=B6nig?=" , Zhihao Cheng , Zhongqiu Han , Sumanth Korikkar , Bill Wendling , Justin Stitt , driver-core@lists.linux.dev, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-sh@vger.kernel.org, linux-s390@vger.kernel.org, gfs2@lists.linux.dev, xen-devel@lists.xenproject.org, linux-mtd@lists.infradead.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Ian Rogers , Felix Kuehling , Alex Deucher , David Airlie , Simona Vetter , Amber Lin Content-Type: text/plain; charset="UTF-8" struct queue embeds a struct kobject (q->kobj) for procfs entries, but procfs_queue_type had no .release callback and uninit_queue() freed q immediately after kfd_procfs_del_queue() called kobject_put(&q->kobj). With CONFIG_DEBUG_KOBJECT_RELEASE=y, this causes a use-after-free. Add kfd_procfs_queue_release() to free struct queue from the kobject release callback, change kfd_procfs_del_queue() to only remove the kobject from sysfs via kobject_del(), and drop the final reference in uninit_queue() via kobject_put(). Check q->kobj.state_in_sysfs before calling kobject_del() in kfd_procfs_del_queue() to avoid warnings if sysfs creation previously failed. Fixes: 6d220a7e7971 ("drm/amdkfd: Add queue information to sysfs") Signed-off-by: Ian Rogers --- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 12 +++++++++--- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index 226f52626e84..8e6136d52a50 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -512,7 +512,15 @@ static const struct sysfs_ops procfs_queue_ops = { .show = kfd_procfs_queue_show, }; +static void kfd_procfs_queue_release(struct kobject *kobj) +{ + struct queue *q = container_of(kobj, struct queue, kobj); + + kfree(q); +} + static const struct kobj_type procfs_queue_type = { + .release = kfd_procfs_queue_release, .sysfs_ops = &procfs_queue_ops, .default_groups = procfs_queue_groups, }; @@ -552,7 +560,6 @@ int kfd_procfs_add_queue(struct queue *q) if (ret < 0) { pr_warn("Creating proc//queues/%u failed", q->properties.queue_id); - kobject_put(&q->kobj); return ret; } @@ -697,11 +704,10 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p) void kfd_procfs_del_queue(struct queue *q) { - if (!q || !q->process->kobj) + if (!q || !q->process || !q->process->kobj || !q->kobj.state_in_sysfs) return; kobject_del(&q->kobj); - kobject_put(&q->kobj); } int kfd_process_create_wq(void) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_queue.c b/drivers/gpu/drm/amd/amdkfd/kfd_queue.c index ae3e7c54014a..4666110aebe0 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_queue.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_queue.c @@ -83,7 +83,10 @@ int init_queue(struct queue **q, const struct queue_properties *properties) void uninit_queue(struct queue *q) { - kfree(q); + if (q && q->kobj.state_initialized) + kobject_put(&q->kobj); + else + kfree(q); } #if IS_ENABLED(CONFIG_HSA_AMD_SVM) -- 2.56.0.313.g2479322e68-goog