From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (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 3129D3624CC for ; Mon, 9 Mar 2026 19:22:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773084138; cv=none; b=W9lXNfhniozjZr8DA8FincySZwaiKpsbrzhV/ZtXehjU5DMTCqYdM4csJTPFPIWTOGEmhM/tTtl4qKcliId7VmS7GlWkZkgROS0pywPI9rBdOeuivkJLtrAfS1mlHB0XX/2kNx5XWSUlMHJfCJll/9ZVP3yd1gKIbQE5HoVwuZI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773084138; c=relaxed/simple; bh=K33C35wIJwlEe0O28qdG8S3iT8DnmYdO70VzMhsnxkI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=WBEh/MusHRwXkkOP6NBFMfL1ejpqv9of5jovgChXhy3D3i3VW8QaS/UKLVU27YQY7AtoglRM8nDLnbq9En8fQSHBN5hCFF/aV4XgVayuDx3SRJjx6VzpBq2GNduXJcMOfYOZeNGcL0CR9CtiIKlm1UiK0sfjgaVwBR5OdEc5vAw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=KdK0MGBS; arc=none smtp.client-ip=209.85.167.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="KdK0MGBS" Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-467161c4b89so496076b6e.3 for ; Mon, 09 Mar 2026 12:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1773084133; x=1773688933; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=8HpMZuPtWn0eUEVrzM2c3iQaTLyHyl2pOMpUueDCTiw=; b=KdK0MGBSsU0aezqy95UPKFdIsUFQBIDGZ95lbPC2eul8Is+w1ij0YWIiXL4bjbVwQa sgQEPQnrLrxPYOMPnrpfLfZat3mv117tPNTKFMQ3GRgolh1vEsozqEuDyLGXyYq0F/d9 JCChMz4ttWCrmBXNe9WIQgMKWc10vk1qFm7ovZXRRWMZa+SDfKIeIDoQatVSX+cD1Mt8 NDQ4PiAIWABskS4Fm0D6iudNdOpq22RLJ06IPL7IurDUSMkX813ruw2KJKYIb1uI0Wvx KXZdSFhHpWGnPMXFI+T6D1mX53KwTsVu87iW4DWXU5S2hwFohsjUR7/KpehMuQs2RM+S GJgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773084133; x=1773688933; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8HpMZuPtWn0eUEVrzM2c3iQaTLyHyl2pOMpUueDCTiw=; b=nU0af6+aXNiUB0GdlFd8NBObxlG+olmEV70Apyk9jKWoJSHQ32RVii20fuUm/F8vrd WcjqRLHYtW8Fnfrjla72uDhemv6kULZ2lqj3hy1P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a:e679 with SMTP id 006d021491bc7-67ba77ae8b4mr3618797eaf.31.1773084132972; Mon, 09 Mar 2026 12:22:12 -0700 (PDT) Received: from [192.168.1.150] ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-67bac14b8c1sm3851538eaf.10.2026.03.09.12.22.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Mar 2026 12:22:11 -0700 (PDT) Message-ID: Date: Mon, 9 Mar 2026 13:22:10 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] io_uring/register.c: fix NULL pointer dereference in io_register_resize_rings To: Linus Torvalds Cc: Hao-Yu Yang , security@kernel.org, io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <42AD516A-B078-40A5-94EE-80739B9883E7@kernel.dk> <453563bb-8dda-471a-901a-30ba9ff3f9c8@kernel.dk> Content-Language: en-US From: Jens Axboe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/9/26 1:03 PM, Linus Torvalds wrote: > On Mon, 9 Mar 2026 at 11:35, Jens Axboe wrote: >> >> --- a/io_uring/register.c >> +++ b/io_uring/register.c >> @@ -575,6 +575,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg) >> * ctx->mmap_lock as well. Likewise, hold the completion lock over the >> * duration of the actual swap. >> */ >> + smp_store_release(&ctx->in_resize, 1); >> mutex_lock(&ctx->mmap_lock); >> spin_lock(&ctx->completion_lock); > > The store-release doesn't actually make sense here. It just says "this > store is visible after all previous stores". > > It can still be delayed arbitraritly, and migrate down into the locked > regions, and be visible to other cpus much later. > > On x86, getting a lock will be a full memory barrier, but that's not > true everywhere else: locks keep things *inside* the locked region > inside the lock, but don't stop things *outside* the locked region > from moving into it. > > End result: the smp_store_release does nothing. You should use a write > barrier (or a smp_store_mb(), but that's expensive). > > But even *that* won't work - because the irq can already be running on > another CPU, and maybe it already tested 'in_resize', and saw a zero, > and then did that > > atomic_or(IORING_SQ_TASKRUN, &ctx->rings->sq_flags); > > afterwards. > >> @@ -647,6 +648,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg) >> if (ctx->sq_data) >> io_sq_thread_unpark(ctx->sq_data); >> >> + smp_store_release(&ctx->in_resize, 0); > > On the release side, the store_release would make sense - the store is > visible to others after all the other stores are done (including, > obviously, the new 'rings' calue) > > But see above. This just doesn't *work*, because the irq - running on > another cpu - will do the flag test and the cts->rings access as two > separate operations. > > All these semantics means that 'in_resize' needs to basically be a lock. > > You can then use 'trylock()' in irq context *around* the whole > sequence of using ctx->rings, to avoid disabling interrupts. Agree - I think Pavel's suggestion to use an rcu protected pointer and have the resize sync rcu is probably better though. As mentioned, resize can be expensive, it's not a hot path operation. the local_work_add() path is extremely hot, however. I'll take a look with fresh eyes tomorrow. -- Jens Axboe