From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C997A3D647E for ; Mon, 17 Aug 2026 09:30:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786959051; cv=none; b=EJRYc6VsJtHLmdgKISEVFcBax5BetW+siwSPpLiME2ZGoxNCPTxdSuX1ubAWjSZifDXn/4lhpwoxUm2K8Yyhp/FMKV/aOF475j50lLR4p1Hl7aq70gaLDqwwFwCj57qaXQT7jTKyYqIXStDNiA1uVck6vdy1L11qvgK2ZS2Bd9g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786959051; c=relaxed/simple; bh=Jb3n91zjR4YXCmRv/8SeLYip2/Z3dG9nr3+qUczMO20=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dqkefk4Zd3z4Ig+CXlnwCrbpX4Q90n5Hq7Iv7Hgyzu/KI3zJ5KPX44GEBnINFrXi8j1tr9SUsKDAAoscJ2s8JUZSRdzZ6Y/T6u3BlLvYKvA5zJ5IsQtSVf7rJfj2BdLHwx1K+N8RI0J2xbBP6A+VBd5UO84Uu3K5nP408avsjWQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=tInXjBes; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tInXjBes" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-47fe76491b8so205415f8f.0 for ; Mon, 17 Aug 2026 02:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786959037; x=1787563837; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Vg/Jh1xJqMzCAOU1msGZarPzfg6nU4pDbrQ+dCgsG9U=; b=tInXjBes8b6pWXavZvPapFPrWiyVYb0TpKrdIRoiXuZD7WIPUhLPYPOJFJk7FljA9o fb+dfFgdlmrVGsQJ70TEXli5wTDD6Hlns8hk1rohZ3cr4zCxqgwwBJ+pTfZRqt3ys17X Qj4fWAjfcT9TkksfyUM7j8FSdRRIa/76CQ3R49gfXVYXXbxZ+eZCC2iUm/R1odoRGBIJ nyMuGtIEtwD1/OgTRKYTRXv/LiXQcHhGCi8UHcqWU+7w7jN02U/kB8rc3DAMNAChPJSO 8Jt+Nm3LE55xI3Jmgh5LlKTYiqC6CKXW9PQ1Eja//oGMwgaHuvf3qBKGG9+E9gcLwU1p b63A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786959037; x=1787563837; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Vg/Jh1xJqMzCAOU1msGZarPzfg6nU4pDbrQ+dCgsG9U=; b=iU4N7aVZwm/6Cq3PtY+JUvUN0jZ1ZWAS0mnXIB6xKsPzf8eGfAdOoqeKLUhWLLMq31 2u/KXPqG54Q4y4/cbhX5Fn80+bMFCgZbsFzBOPm+OOnr4LSTVSJtBoz5RSCYROJYVFov S5NBlNMVOpuu7EpYnxBddDoKdCLP2V3u6mNok8wpPPF2knl2HUQhkePuZIviyS07BjXb drMYvylsyf3JUN5giGPndIdlg2mLMsZRZ7box2eszwXfAGBcg+0/c+yTplt1/PRKFDn9 Qs+skvNESD2hdTowHlw5RY1I3g1re662ODAtlcML9ooN0FhwGS2/PbKbLjemUuUGaRj1 3Z9g== X-Forwarded-Encrypted: i=1; AHgh+RqNVJfW+DOQ/XlA/ggV9ibfHCIZrB/8LaYb/n1w0d/tE0sODJrWgcVnVupiRrmBYwWDd04Zduuy4/CWJUI=@vger.kernel.org X-Gm-Message-State: AOJu0YwPM4qsYWQkSO2uRRK8Hv72PFRALEUMYb/jqCPhLfRjmbakSHY8 jHgH/xFFBa+wric9yNFG2K7G19vwwFmYjr4U//tc68uxmMiC1MQM/p+W+5c/rg== X-Gm-Gg: AR+sD10/ejdmpj2jboj8XwtzFKXHs8rDWcQgeYnVq9g9m8OlEydVChmLSYg/ctyMAtL NfiWaC5EqFILTWEkCEdwt51hOEBetT4EjYZrAiqAwmGAGa2Rm2MJ5euzUPQRvz+GDfzgthcT50b MrYL1/ZSyUwZtlXQAGaFRgRi3xqBF/acZeVSIID1mK6pxRM80ULDcfkYXkaqR1ifWAUkMw4QK8L RMh34Y2Gm6bjNWAphv/DB5UGzRFy5TXzcHiL8Qpjo2ZyQHicS2uJ1rjLruXQuIhwP3H7kWOHMl1 qOrzub+CynHW+LBbnDXbdWUEGxyE+OdPPTSU1lFEm0mC4KLk6hGzWforgTUcshNMidy6ALxssNk QMlMex8pG7iW93gjWAqQ1F7SXxQKv2EKIsqQ4YQq4PIMx7tenwkx3P8T49x8x+Bye0zh0ATGlcj rGprJZ7cVR2FmUPpHxWviyD+ds2WuvWxxmDRg3RVnoi5dwrfbCm82GcDPCaSlwflnWf+uaE8A2Z irjHeYS8hdyZR3QuTagvAxWW5VdZrrglnZl3DD81+8fUjWckQ4X4lXABYd5EAQLzxxwmQ== X-Received: by 2002:a05:600c:1d23:b0:499:59a1:96f7 with SMTP id 5b1f17b1804b1-4998792aab8mr184494205e9.1.1786959036570; Mon, 17 Aug 2026 02:30:36 -0700 (PDT) Received: from OrangePi5-Plus.BB-HOME (20014C4E1B8FC50027494B64639367E4.dsl.pool.telekom.hu. [2001:4c4e:1b8f:c500:2749:4b64:6393:67e4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482a5a31396sm2474365f8f.2.2026.08.17.02.30.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2026 02:30:36 -0700 (PDT) From: Igor Paunovic To: Triet Hoang , Tomeu Vizoso Cc: Igor Paunovic , Oded Gabbay , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] drm/rocket: Check allocations before use Date: Mon, 17 Aug 2026 11:30:04 +0200 Message-ID: <20260817093009.22359-1-royalnet026@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260817072045.876042-1-triet.hoang.dev@gmail.com> References: <20260817055315.C9AA41F000E9@smtp.kernel.org> <20260817072045.876042-1-triet.hoang.dev@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi Triet, Thanks for picking this up -- the rocket driver has few enough eyes on it that allocation-check patches are welcome. The rocket_job_push() half looks right to me. The early return skips the err: label, but bos is NULL there anyway, and the caller (rocket_ioctl_submit_job()) takes the goto out_cleanup_job path, which does drm_sched_job_cleanup() and rocket_job_put(). Nothing is leaked and nothing is armed yet, so returning early is safe. On rocket_job_open(), the v2 change fixes the error path, but I think it only covers half of what was reported. The other half is still there: the array leaks on a single-core device even when nothing fails. drm_sched_entity_init() stores the caller's array only when it will actually need it: entity->sched_list = num_sched_list > 1 ? sched_list : NULL; (drivers/gpu/drm/scheduler/sched_entity.c, unchanged in current mainline). And rocket_job_close() frees exactly that field: kfree(entity->sched_list); drm_sched_entity_destroy(entity); So when rdev->num_cores == 1, drm_sched_entity_init() succeeds, entity->sched_list is NULL, rocket_job_close() frees NULL, and the array that rocket_job_open() allocated is never freed. One pointer per open(), unbounded across open/close cycles. That is not a hypothetical configuration. The RK3576 series currently on the list enables exactly one core on the ROCK 4D -- its commit message says so in as many words ("Only rknn_core_0 is enabled: the driver binds one core per node and the second core is left to whoever can test it"). Any RK3588 DT that leaves a single core enabled lands in the same place. I would suggest not depending on drm_sched_entity_init()'s internal choice about sched_list at all: keep the pointer in rocket_file_priv and free it unconditionally in rocket_job_close(). That covers one core and many cores with the same line, and it stops rocket_job_close() from reaching into a scheduler-internal field to decide what it owns. But that is a bigger change than the one you set out to make, so it may be better as a separate patch -- Tomeu's call. Two smaller things: - With the check added, ret is assigned unconditionally from drm_sched_entity_init(), so the "int ret = 0" initialiser in v2 is no longer doing anything. - Heads-up on collision: I have a patch in flight that touches these same lines of rocket_job_open() ("accel/rocket: keep core slots stable across unbind and rebind", part of a two-patch lifecycle series). Whichever of us lands first, the other rebases -- I am happy for that to be me. Worth mentioning because in my version the count passed to drm_sched_entity_init() is the number of *live* cores, so once cores are unbound down to one, the leak above starts happening on a multi-core board too, at runtime. I have not run your patch, so no tag from me. If it would help, I can test it on RK3588 with three cores and again with two of them unbound, and check the single-core case with kmemleak. Regards, Igor