From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 BB9ED3B19D2 for ; Wed, 17 Jun 2026 07:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781682089; cv=none; b=Gp6/V9p7M/HxmGORKU+XrLLdW2idIoHFcqoadc3qualMLUAZqnfrFGui82451eZagSZlTWGLT0PnLF+5+Z1UfOQx4VKXH1MKwDLgSU26NGIw6vkfqiOIaQjatB19Taq95CMGCg6iWRi1fen2pJwr+3XRmdwbmKN7Fq75Rk730Ms= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781682089; c=relaxed/simple; bh=VfvN2NB/wnjHyZfBZHt+ChcGGwIjmvnR6Eg88MC6Nvc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EOIDFxX4i04JxWKaFZXQd+rsGpmNkuaSQFDhhtxXAme5nYP/VcU9KBIBPs1wlPY3z+xuNUmEDKckOH1TUl7Q4QIGlz6TVtE7Ga286xzm2/+LU5K3o8iLWs+NEeaTS/gTBN+ZUW0DBj6HdqTP50mcMd/Xf4Dp3E3x4lAWrKqgRvA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=0sec.ai; spf=pass smtp.mailfrom=0sec.ai; dkim=temperror (0-bit key) header.d=0sec.ai header.i=@0sec.ai header.b=UoXLsCoP; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=0sec.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0sec.ai Authentication-Results: smtp.subspace.kernel.org; dkim=temperror (0-bit key) header.d=0sec.ai header.i=@0sec.ai header.b="UoXLsCoP" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-45eeea039ebso3091628f8f.1 for ; Wed, 17 Jun 2026 00:41:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=0sec.ai; s=google; t=1781682086; x=1782286886; 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; bh=JTKHX6NCn7vn/+gvhr4Pc1ts3vNTjwaHvcnrlwVBhzs=; b=UoXLsCoPLwtM/ZQdao4T6xnz+OtL3jt8kfU7NvD7O/Isk5OydbV1r2i4P7/2k7paZI oOG8r9nefFoRIN/jb3mt48lB9y4FNtTo4U1d3EEBz6AEKMoL2G53SxrpuCuNI16gWCUB /szNuC3/8aat2VA1KCj2k5W3E/lvs9PPzJv07A9dsSsZvukcU3j72hj2WUqG1yGwiSyC k9mkVhk1hwYa5TXLZo8Es6RiqTwLfH6HYZZIlSH1pna0T9w0wDwctiU+5inaXe6HeGVy S7bu7mWGEw3E88fWcbqdkvbI6pJKfHM80bz4OBTjrVN6vRCkKW7HOblLf95hTIolBYVb rxZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781682086; x=1782286886; 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; bh=JTKHX6NCn7vn/+gvhr4Pc1ts3vNTjwaHvcnrlwVBhzs=; b=Bsq/UWvFpczL3ez32IZJfRPcsO7grLC0jyTKcUwjaV+kszNWfH7z/97Pw9ZKZ12U2S 2AFDo4LyYdlPvskwPUmT7kqz0l+VMKezgDexP2FuUByv2aDlGX4FEsfLDbvHmlf6VW+r chuydoPnu89O8yRdJQUtmJrk6xieqmKuWx+hSrf2oZSKirGz7XrDI+iA8fWObrBq8CSZ N63Zdp03ovUvp7vDjjkkve8134Tzyp6P2IQehboxykGxFo1BnUUZauy9RqkblGYIydER u5KEzVZbEUUn5aWrjjYxHKtW0oM/erjl4LalH6/6JJfTA1cKto8X9LE6a19XgKcaYgHx TP9Q== X-Forwarded-Encrypted: i=1; AFNElJ8jQgoLSwXWfLdG0sD2xBMTDS+Rhx3vxNkKt+yWN2TJavfSnv3hVvu6a7/YrRo7/Nzy/Fy2QlgYYvCNBz0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxg3F409rIqQrNZq4E9Q6PDCYgUUZe05RonBP5QnPBUEqofHZy1 ZIw7XPNgw7gMDNn+bUvcF8pc0gbUKi+m8wO4LTEY5TEkyQlKZjUQO3SPetBb6t+8FwtEFVFF9mo lGnLvo6j2 X-Gm-Gg: AfdE7cnKsl9j6Ouc60B17CUl6Qrl3zv/e92t2Tmvp75H2MmgnrpfLkxEDo2MRF61MZt W9bwtDQ9Ez7BM+FEzyi+iIXQZL3+ubPq+SJ1RAWvA9/a+msRSDy9+S5/7KbhGhe077CFTUhjMO+ k+5tM7jB0yRnmyLHVqzqXUnjpSnPofSj69MfZYlPy1eyIvN6J6dwt316972bg4FbdPRghS+bpw5 +9XWE1qN8umJOaFkwL+828gtbmvPWVvNWczeZdTYgkS+QBAuiD9YX2yNwMWZkzRiFZbRpK+oyTO S5V5iULE/ChOTH3dZrsBxygVfbsCQoDkDlPS4EuYMBW85G7su7cECcw9rxa7MRvPFY6fQykZh9/ gAW0IgDsLtNYtpUYRgEwRdO704fjgsW9tRZZDpVp+HM5i9ZHRUYrduXSlx9lhIjtmc7tPeQ8RWi e/64DxE1DKH1ST1ngd92xcWFitm1AdwqGYVYKAaM40hfWX7aSkOrr1pyZNNYpj7jtqGXqXJIPGZ LXKwZs5T1xM503Ay9vieYql6iGGofL5AAY= X-Received: by 2002:a5d:6a87:0:b0:460:25f3:b25a with SMTP id ffacd0b85a97d-46238f980ccmr3573765f8f.34.1781682085876; Wed, 17 Jun 2026 00:41:25 -0700 (PDT) Received: from PeakBook-Mini.tail8e484.ts.net ([178.197.218.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4606f26434dsm52677098f8f.1.2026.06.17.00.41.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 Jun 2026 00:41:24 -0700 (PDT) From: Doruk Tan Ozturk To: neil.armstrong@linaro.org Cc: mchehab@kernel.org, gregkh@linuxfoundation.org, hverkuil@kernel.org, jbrunet@baylibre.com, martin.blumenstingl@googlemail.com, linux-media@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Doruk Tan Ozturk Subject: Re: [PATCH v2] media: meson: vdec: fix use-after-free of decode work in stop/close path Date: Wed, 17 Jun 2026 09:41:23 +0200 Message-ID: <20260617074123.32464-1-doruk@0sec.ai> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260616074952.93076-1-doruk@0sec.ai> References: <20260616074952.93076-1-doruk@0sec.ai> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Please drop v1 and v2 -- both are wrong, and the sashiko review was right about the deadlock. The underlying bug is real: vdec_close() does kfree(sess) (and v4l2_m2m_ctx_release() frees sess->m2m_ctx) without cancelling sess->esparser_queue_work, whose worker dereferences sess->lock and sess->m2m_ctx -> UAF if it is pending/running at teardown. But cancelling on the streamoff/poweroff path can't work: 1) Deadlock. The worker takes sess->lock. For an m2m fh the ioctl core takes m2m_ctx->q_lock (== sess->lock) for VIDIOC_STREAMOFF and holds it across the handler, so vdec_stop_streaming() -> vdec_poweroff() already runs under sess->lock; cancel_work_sync() there waits on a worker blocked on that same lock. 2) Use-after-power-down. v2 also cancelled after vdec_ops->stop(), which power-gates VDEC1 (__vdec_1_stop()), while the worker still reads a VDEC1 register (vdec_1_vififo_level() -> VLD_MEM_VIFIFO_LEVEL). The only deadlock-free point I see is vdec_close() (the ->release fop, not under sess->lock), cancelling before v4l2_m2m_ctx_release() -- but that still leaves the threaded VDEC ISR (amvdec_dst_buf_done() -> schedule_work()) able to re-arm the worker, and there are adjacent teardown issues (esparser_isr() vs the dos_parser_clk disable; vdec_decoder_cmd()/esparser_queue_eos() without sess->lock). I don't have Meson hardware to validate a corrected fix. Is a vdec_close()-only cancel (plus quiescing the VDEC IRQ outside sess->lock) the direction you'd want, or would you rather take it given the HW testing and the surrounding teardown concerns? Doruk