From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.48]) (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 2D9EB372EDD for ; Wed, 8 Jul 2026 15:50:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783525850; cv=none; b=VVKLDrJw4ijF/hRmZefoE9ZyffKW6ZWYaM1vg55a6o/y7Y+4gIQpirXdhyUEHn9Qg5a6SI/JndxXEhEqaVvZabKW8WyygsT3CkdJX3fdgr3ANayJwpUV1uNNGU7khRXyDo2ObROaNCAYkzHu7o7gP8gPtZXz/sL39jlCD3iZBtw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783525850; c=relaxed/simple; bh=W+9LTNT3r4t1s73YprNuG5DwYdgfPjuZSmgyXHRohEM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=pzCJyrIDsA+PKXfF6THAbDyf+Fo7lDSFts3PCwAb+IMviTrvfMKfVwK2UgZFNSYOyXf+p3YL/y0rO6wxsdEsh/APUnlc4s3OGDrWxK4bdH5jz54NnR7d8NWbkbAZ6LA51pYR8/d2iA42RIDX4fqH2iw0KE2NpmXGYXAO5Vp4MHQ= 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.20251104.gappssmtp.com header.i=@kernel-dk.20251104.gappssmtp.com header.b=mjGDCQ7O; arc=none smtp.client-ip=209.85.161.48 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.20251104.gappssmtp.com header.i=@kernel-dk.20251104.gappssmtp.com header.b="mjGDCQ7O" Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-6a1888969ddso462297eaf.3 for ; Wed, 08 Jul 2026 08:50:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20251104.gappssmtp.com; s=20251104; t=1783525847; x=1784130647; darn=vger.kernel.org; h=content-transfer-encoding:content-type: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 :content-type; bh=uwINqnUpR+2ewKtt6aPXAWXCQ+z8muVF+g3BPgX9RZg=; b=mjGDCQ7O/jaA/0O9/iWrQ1QH9tm9Lt/5DdVLhS7BeP7O/YclteaMBVz4nrSq0Edleo s0nngqvzqlOQ9vKx00W4QJDu8eWHcmZz1ct3ro0BkHXZ7qoxINtrR53/v/iyxosO0qYm +dN7WFVM6vxuhiVi1BjWBBmeeyAsmA/o2hNZeZH+7Z49rWmBjtjVktLvOk0eMvZ3aNff wT7l65zy+F76vKoHrvXmMF5Cxlo5HCAa+IS/xSM1WfU2uX/mUka3z5vzmR25GWSrfW6Q 6UWwyTIB9LI2H3d2FTiSCfogqGqpW7Fz9jZunxVrh/kd9T4ydYsifhoJZr3ljYoeNI9d uyjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783525847; x=1784130647; h=content-transfer-encoding:content-type: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:content-type; bh=uwINqnUpR+2ewKtt6aPXAWXCQ+z8muVF+g3BPgX9RZg=; b=gJ1IG7KT7q4MpIeupqtRyV9wtRYd0KW4S1rPKi4jEu+lTG8f9NrZZXGhfSob43FcxP WuDd6b/K2XeW7346WWFe8idD+Cq16/enNDoL9/AIKblZNFRvRPYdiIyuOlEQmqSC1EFw UoUhCR3j1s4w11MzaFhcbsRRbTL/tyZ46zVB0OwbUu/7K4v4IK2h57JeJyaeUrTPkR75 pXDSFDa3QHWrSBOQH91/pWnvY6GaVja0BxpxiudIQKfOOfQVJE/FWromVVOysj/SvMpF LDQsdcbEmFlk21iYWbnCn0Pwdt7LcR6CmsiRQ/3/NlTtALyyCn1ULZtpawbvnWwBkYjy j7yA== X-Gm-Message-State: AOJu0YxGY/JuEeGY6SXZDltnk8L9+mzLyxYyd7AbB/rigTrj5Hfv8Sqx HI1MhxEBpguwRaqlgAA6pK2B6vRQNBgqMsE18Ovr80if6j9nZoR4szgZEh0HUMigfP8= X-Gm-Gg: AfdE7cnDFycyqBtLodPAVJLiiBvIh+KK8JnwAUdsiTZGbkXoNrnsqRnGeyY2F5fMr5z S4P9BiGmaU9UUP4QI2D5CAIs0LU9HCoFNzxU4CW5G/NM8M+yF0EneQ9e1kYhKAneMB8hF9Qm1IC cMZwtb+FWCAKN+PELdCKhlpMo22eyYaCbx8Ym+EiXFfBS+1fFQrqaHFS1Nk8yIv4lH0HzwBEtjU Bcz3Qb6D5Wg24AF9s7a5XLUO2dxgyV+WHcnPbhinPaki8SoWeXXL25iR+Y/EO5/59mFc7K0/VGC O/mQGHyRSqqkQcPykrdyDE1k1tj1wuSH50kBEHKiZHz/egg73esGBO/MSmQit5phDUU6a11Yld1 QokVgu3DMowrUgTqjuUyQ6ZZ3bNwxTxei8rZk1cvrdId2J51GOdkJLy/UeYa4OCPHsAdfKO9/ob J4vFx9eav57t9UQd8jULjumMwFfFIegWj09EkWWifWF0eiwb83g2zvVBrzjNdvvimqZYEmz6o= X-Received: by 2002:a05:6820:2915:b0:6a1:3dd5:adf2 with SMTP id 006d021491bc7-6a36da8fc74mr2075423eaf.53.1783525847011; Wed, 08 Jul 2026 08:50:47 -0700 (PDT) Received: from [192.168.1.150] ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-44cfb1d1ff0sm17018155fac.7.2026.07.08.08.50.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jul 2026 08:50:46 -0700 (PDT) Message-ID: <18ebc6be-f76e-43f5-ba73-8ab4f83c3b2b@kernel.dk> Date: Wed, 8 Jul 2026 09:50:45 -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] io_uring/net: clear stale vec on buffer peek error after expansion To: Gabriel Krisman Bertazi , Feng Xue , "io-uring@vger.kernel.org" Cc: "linux-kernel@vger.kernel.org" , Pavel Begunkov References: <87ldblwkm5.fsf@mailhost.krisman.be> Content-Language: en-US From: Jens Axboe In-Reply-To: <87ldblwkm5.fsf@mailhost.krisman.be> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 7/8/26 9:45 AM, Gabriel Krisman Bertazi wrote: > Feng Xue writes: > >> Subject: [PATCH] io_uring/net: clear stale vec on buffer peek error after expansion >> >> When io_ring_buffers_peek() expands the iovec array during a bundle >> recv retry, it frees the old array (A) and allocates a new one (B). >> If access_ok() then fails, B is also freed and -EFAULT is returned. >> >> The callers io_recv_buf_select() and io_send_select_buffer() only >> update kmsg->vec.iovec on success, so on this error path vec.iovec >> still points to freed A. The stale pointer survives into the netmsg >> alloc cache via io_netmsg_recycle() (vec.nr < IO_VEC_CACHE_SOFT_CAP >> so io_vec_free is not called). A subsequent bundle operation reuses >> the cached hdr, sees vec.iovec non-NULL, sets REQ_F_NEED_CLEANUP, >> and passes the dangling pointer back to io_ring_buffers_peek() ? >> which writes iovec entries to freed memory (use-after-free). >> >> If the alloc cache is full, the alternative cleanup path through >> io_clean_op() ? io_vec_free() kfree()s the already-freed A >> (double-free). >> >> Fix this by NULLing vec.iovec and zeroing vec.nr on the error path >> when expansion occurred (detected by arg.iovs != kmsg->vec.iovec). >> Do not call io_vec_free() here ? A is already freed by the expansion >> block, so kfree()ing it again would itself be a double-free. >> >> Apply the same fix to io_send_select_buffer() which has the identical >> update-after-success pattern. > > cleaning in the caller makes the issue much more likely to happen again > in a future use of this function. It would be better to fix the bad > semantics of io_ring_buffers_peek instead. > > In fact, this is exactly the point of this patch, which I believe > already fixed this issue: > > https://lore.kernel.org/io-uring/178338543579.49877.9882374687710864124.b4-ty@b4/T/#t Indeed, this version is just a terrible LLM version of trying to fix the same thing, but not understanding the issue. -- Jens Axboe