From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 AC1AE2D5412 for ; Mon, 6 Jul 2026 19:01:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783364489; cv=none; b=EBz2m+S3KRKU8nitZbZgj+4GvvujFVbyzhLMxxEmpvL+xYOZ1LRVeCBbZjd9s/iAXb1ox+nJNoLzMX42cKr3PK/Eoiy+5MBJLaAclM0GrX90wtgALQaxHfUqz+JFZZ1FUgmMKzPVt6JGKhTYgH0zWVh41QSBvr+4WcOqO/kioEs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783364489; c=relaxed/simple; bh=8z3H5pOmv9FJzzWGKGMRL22BIuJrrbYJYmqaNpUMp2o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ijSliKbd6QfJZT76LGDxzd0vzkKVkTPdsva3dbQWaz75qrkB8hdzmjUFk4iXwO+AMKvQ5V2Eg/HcToI8eO9OS0VvkBOxqOGfmcYGEeB924hKs3ONtmK330W8KvlE4b2+f53vmMMvM6VQHhciHWe7k4xr8nlXebdsyaL3YXOnGf0= 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=B3rYRZLN; arc=none smtp.client-ip=209.85.210.169 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="B3rYRZLN" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-84794e800f4so1927900b3a.0 for ; Mon, 06 Jul 2026 12:01:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783364487; x=1783969287; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=2KMT6UZ2QSOc0un8dMggiel2syWYq8q93mY2wWgeDaQ=; b=B3rYRZLN2az3M0Cg0QR4rv6bdmTUxE7mnRR6RSxM6C0tEGyOJYmvO92F20gkmKWkb6 8qFDZfFjEFxM9osGDCBZP/OhS9paDspQ0QOxRRyJ1Q4Lgd6Kg0XuhWgUAw9jgFGBpxyX ocVWfpAJiufKSixPcT+N/XsPmOdxEvRfGATGQAmFnXjTk6loKoH2WHsCrXMS4IBCLXGe fZocWICmxHuQmqEl/WRQ5acxyY9Z66ovUyROFHmOddF81yoOdtIPm1bZuBX8FFruMb55 gvYk1uhuPaePsNOUo8LDh30AOs2f20KKXAR5b2s8cqAD0SfNLsYBMCnmWZHML8P7Nxnd x+3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783364487; x=1783969287; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=2KMT6UZ2QSOc0un8dMggiel2syWYq8q93mY2wWgeDaQ=; b=WD3D7JwJSry9ii4A0vu3cA0ppd729qiFgK4O/Km2uDFQpTb9btOaNvNrLcoNRc3PqA ASYGLNwpr5453hEhMlGSjAZIKnF1KJ5LGHgmAFpeSvLNynWndhN8FoLBqEOoDAGS+S2I 6ifP04N3tD8LdDFtvK72YAgol3+xMKXxEt4NcejZ2E93mr6JoD47BFmDwdLuK2HFR/7o CmuPO6M8bW1oyZ2bREgRhRXVn6uqUXnMuIDLHwkLKKpHMS87zzsR5IL1RPACAzbgRS1H UGewCc+/OnW/d4r6kw9Xln791dAw57vycDwKDqm7yLv1qhF4F6P1c3aad8+WF5NDk4TI KCUw== X-Gm-Message-State: AOJu0YxjC1mahy5A03dOld+e5uKaIi4fhdS1O1EHSkbdAch0F74Y2e/A gIUOH3SSq0rHZhCL3zccW38gGLcb+xhlqaVIuntYJzpLzf/qOvU4ciwxvFEp3qUtRN0= X-Gm-Gg: AfdE7clNO5a3C7Wu91iFD/xQsvFG0RQs8sc4vUehlPDKj005NCP63NnbXjCT1LNJ1HS aCkDfVCDFZIJ3r71mtWXskULCBZYHLWb94adYlUnyhcPK/MtevxHoq7dr2O+sWRe66Fgmw3fLtK NQf3mcFRnbAVlyL0GqvzfAk3dE9opLBniC8PoCcFlaQF7Z0Ems02XfijEnCeqSrUaVj+kpStIXb 49BwEhC8UahUjgQmZqlO9EuPiCLVBUMu3DDhFWcWBdOUEjfRR0OZA3CQMPq4wZcJmixk0ykx8Jo WsuEW2OJJALkHmdOxXNGCmGOhIBKzGIL4mwMaVmAal1ALbt2Vbma6tnyP5e8IQRvFPSIi02CKcd XxazTUziJeAZAd0IGR1A9ev1+ZTDYh6a/B1sLn36/PPKurhYhurt9hCX7/YZBCHvH0dkmKTy18t MQhDX6nZYaLGxWFAUtYoYhBVcriI6K8hmQ69E3NE8= X-Received: by 2002:a05:6a00:300d:b0:845:e3af:dde9 with SMTP id d2e1a72fcca58-84826d3f6c8mr1825273b3a.38.1783364486847; Mon, 06 Jul 2026 12:01:26 -0700 (PDT) Received: from naup-virtual-machine ([140.113.139.102]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-847f6db0eaasm4256912b3a.52.2026.07.06.12.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 12:01:26 -0700 (PDT) Date: Tue, 7 Jul 2026 03:01:23 +0800 From: Hao-Yu Yang To: linux-kernel@vger.kernel.org Cc: axboe@kernel.dk, io-uring@vger.kernel.org Subject: Re: [PATCH v2] io_uring: fix dangling iovec after provided-buffer bundle grow failure Message-ID: References: <20260706183304.919275-1-naup96721@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260706183304.919275-1-naup96721@gmail.com> On Tue, Jul 07, 2026 at 02:33:04AM +0800, Hao-Yu Yang wrote: > When growing a provided-buffer bundle, the old cached iovec is freed > before the new buffers have all been validated. If validation fails, the > request still points at the freed iovec, which can be freed again during > completion cleanup. > > BUG: KASAN: double-free in io_vec_free+0x2c/0x90 > Freed by task 73: > kfree+0x104/0x3b0 > io_vec_free+0x2c/0x90 > __io_submit_flush_completions+0xc03/0x1e40 > io_submit_sqes+0xdb5/0x2310 > > Allocated by task 73: > io_ring_buffers_peek+0x559/0xc60 > io_buffers_select+0x1c1/0x460 > io_send+0x770/0x1050 > > Fix this by deferring the free of the old cached iovec until validation > has succeeded. On failure, free the newly allocated iovec and leave the > request pointing at the original one. > > change log: > v2: slimming v1 patch > > Fixes: 46800585ae04 ("io_uring/kbuf: validate ring provided buffer addresses with access_ok()") > Signed-off-by: Hao-Yu Yang > --- > io_uring/kbuf.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c > index 3cd29477fff2..b6b969b55e12 100644 > --- a/io_uring/kbuf.c > +++ b/io_uring/kbuf.c > @@ -287,8 +287,6 @@ static int io_ring_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg, > iov = kmalloc_objs(struct iovec, nr_avail); > if (unlikely(!iov)) > return -ENOMEM; > - if (arg->mode & KBUF_MODE_FREE) > - kfree(arg->iovs); > arg->iovs = iov; > nr_iovs = nr_avail; > } else if (nr_avail < nr_iovs) { > @@ -330,6 +328,9 @@ static int io_ring_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg, > buf = io_ring_head_to_buf(br, ++head, bl->mask); > } while (--nr_iovs); > > + if (arg->mode & KBUF_MODE_FREE) > + kfree(arg->iovs); > + > if (head == tail) > req->flags |= REQ_F_BL_EMPTY; > > -- > 2.34.1 > Just sent this v2 patch and wait for this patch merge? I need to do anything else?