From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa2-f35.google.com (mail-oa2-f35.google.com [74.125.231.99]) (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 23C043033E6 for ; Fri, 2 Oct 2026 14:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.231.99 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790952955; cv=none; b=QbOvb3IOsaPvWtt5Yr0XYmzKjajA6nZew48wkkrcgjjxH7AbIEaI8drdE4vZhQx+vKQmtf4ZCx8F75GGw5HxPaDBIM8eQigpOlPhpc9DzPQ5JwrlrFfZYIn9jOPrNRtzW8rda9byVcwCQVhL1PGREixPz/usam9eqaiQI/BqJJg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790952955; c=relaxed/simple; bh=mWawWoT/4zGtCooTZRrFjQzDVEsQ87rz1F1yEWua8Jw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=K3CW8U5bteyxL268jvIi8NmEz1tl/mKSHNXdiwsMkwGsG+K54hFEFDFO3f+wQdGBwL5VYxoDrK+FO4tRNU8aMvinHdwx+ILkF0B3f8x8vlO+7lAwW6z76nYxfsR2rsNf9v+tGPUwdHmQwiaqpOXi/duRTWVs2S1o1bxKop8uDOQ= 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=WIcj47sU; arc=none smtp.client-ip=74.125.231.99 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="WIcj47sU" Received: by mail-oa2-f35.google.com with SMTP id 586e51a60fabf-492d8c4add0so11239fac.0 for ; Fri, 02 Oct 2026 07:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20251104.gappssmtp.com; s=20251104; t=1790952951; x=1791557751; 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=+aS1nFHs1o26b9G5lmQi2V+h1cf11SB88eiBbPfTjO4=; b=WIcj47sUpRFBtqjA0GLnqxuCUFXZM9zyHz5gg4gBKWQx6HMuiZ8lRfhKIY5HE+sUxw RpzuxqokkIjOVEwQHyhZuDe1L1h3wvnOH4kwi9sJKMQ3sscQhA17KGS44KU1BvOxwmEy npKm3GOYK8Q5K9UC9C08WBbCqLi0bnZKYG1dVyKcFpruoSnNhfoMyX0o4fZcyTzpUHUa adcU3ZG6vU4pclmuuG2KHBidl33DCRFxIQ+wQQPXr4lMNI65bVyn9U2fdGIEtg5GjXu2 /mxjwVwp2qBKTIsPlp4kDQ0ktwYC6DxO1Q7o6az586tuKp1kmv0KruFNwtEdPnq+op93 kTGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790952951; x=1791557751; 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=+aS1nFHs1o26b9G5lmQi2V+h1cf11SB88eiBbPfTjO4=; b=POaASEGjjpnp9X5Bfmedjj1oc7FwQgCovjdtvzj+a+yrgvrIPgDp/xG+p8N4x/d9S5 Hc8T5wkWd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GGXa0fKPrSe53JJ/72AAHAtUifcz3aHnWg= X-Received: by 2002:a05:6808:1828:b0:4f3:68d6:f12c with SMTP id 5614622812f47-4f528de5ecfmr2380933b6e.24.1790952950725; Fri, 02 Oct 2026 07:55:50 -0700 (PDT) Received: from [192.168.2.38] ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4f5243d47absm1998187b6e.8.2026.10.02.07.55.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 02 Oct 2026 07:55:50 -0700 (PDT) Message-ID: Date: Fri, 2 Oct 2026 08:55:49 -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: fix out-of-bounds bvec access in io_vec_fill_kern_bvec To: Ming Lei , =?UTF-8?Q?=C3=96mer_Mete_Kaya?= Cc: Gabriel Krisman Bertazi , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261001143003.755790-1-omermetekaya0@gmail.com> <87se2pwhzh.fsf@mailhost.krisman.be> <20874bd2-f827-4ef8-9855-dc8aaec874fa@gmail.com> Content-Language: en-US From: Jens Axboe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 10/2/26 12:04 AM, Ming Lei wrote: > On Thu, Oct 1, 2026 at 2:55?PM ?mer Mete Kaya wrote: >> >> >> >> On 10/1/26 18:36, Gabriel Krisman Bertazi wrote: >>> ?mer Mete Kaya writes: >>> >>>> for_each_mp_bvec() dereferences src_bvec[bi_idx] in the loop condition >>>> before the body is entered, with no guard against bi_idx reaching >>>> imu->nr_bvecs. iov_kern_bvec_size() stops iterating when i reaches >>>> imu->nr_bvecs even if bi_size is still non-zero, so the fill loop can >>>> walk past the end of the bvec array and overrun res_bvec[]. >>>> >>>> Open-code the loop with an explicit bi_idx < imu->nr_bvecs check before >>>> the dereference, matching the termination condition in >>>> iov_kern_bvec_size(). >>> >>> Do you have a reproducer? This should be checked in iov_kern_bvec_size. >>> We make sure it doesn't go through imu->len which should match bv_len, >>> IIUC. >> >> Yes I checked more and looks like the *bug* is unreachable via existing >> in-tree callers.>> >>>> Fixes: 1045afae4b88 ("io_uring: support vectored kernel fixed buffer") >> >> It doesnt fix something broken actually, more like a defensive refactoring. >> >>>> Signed-off-by: ?mer Mete Kaya >>>> --- >>>> io_uring/rsrc.c | 7 ++++++- >>>> 1 file changed, 6 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c >>>> index 51b46e624..3d29a0c7b 100644 >>>> --- a/io_uring/rsrc.c >>>> +++ b/io_uring/rsrc.c >>>> @@ -1614,8 +1614,13 @@ static int io_vec_fill_kern_bvec(int ddir, struct iov_iter *iter, >>>> struct bio_vec bv; >>>> >>>> bvec_iter_advance(src_bvec, &bi, offset); >>>> - for_each_mp_bvec(bv, src_bvec, bi, bi) >>>> + while (bi.bi_size) { >>> >>> bi.bi_size is the first condition of for_each_mp_bvec. Do you really >>> need an open coded loop? If there is an issue, can we just add the >>> check below? >> >> mp_bvec_iter_bvec() is called in the for-loop condition not the body: >> >> for (iter = (start); >> (iter).bi_size && >> ((bvl = mp_bvec_iter_bvec((bio_vec), (iter))), 1); <-*** >> bvec_iter_advance_single(...)) >> >> src_bvec[bi_idx] is dereferenced before the loop body is entered. >> A check inside the body executes after the out-of-bounds read has >> already occurred. The open-coded loop is the way to check bi_idx >> before the dereference. The question is "should the kernel be defensive >> itself or trust the callers?". If you find these kinds of defensive >> controls unnecessary, happy to withdraw the patch instead of releasing v2. > > bio/bvec iterator is written in this way from begining. > > So it looks you should work on improving the iterator helper, instead > of open code for the single user only. Indeed, it's a generic helper. If there's a potential issue in that helper, then that is where the fix should go - not having users open-code the iteration. So please take a look at the root cause instead, I'll ignore this patch. -- Jens Axboe