From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD953397339 for ; Wed, 26 Aug 2026 18:18:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787768340; cv=none; b=sd/MBHpxZtATa645WrW8cmJhxY5RfVIZO0f7vThNucwmaLCNuXDMW/WGT/TYl9RuzQEaSGIOGh49Spf8nyQegor/qqIdxslqY6SHpwr4Qyw5Ul7eSdoT/T75ndHNuWYYkUGkjkwIQCKcWme0WaGtBTNckKKRY1purdwQv+N3W6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787768340; c=relaxed/simple; bh=L8KyPPggjfQc0sjy7Gw8VvJOeao1dLD5GRpwQSbnwJU=; h=From:To:cc:Subject:MIME-Version:Content-Type:Date:Message-ID; b=RuHWvX2VZiMWY71hIWWB6F8A46sEgpdyR8xe52NcNjBGBrUsFlXoUlQftrPNXAEOvsFbwMWsmLNlMiT93QGTgDp9HEHgv4kggmQlgfnQ8fRqq4VEIgMhi7eU4MZdX2QBDba+nV2ouji1dZ1pBDfw+Y+7TXu6J7n+INxfyZEcUaM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TF99LeOG; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TF99LeOG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787768328; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gYOiX+GeRVSWt3hpKqETUz5lFrLQkAWNPhdRzqcUUOE=; b=TF99LeOGYQmAlncRs/WJkPPrwu6roAAeSBCsNNwUIujzyW72SS/bEBJHGG9DLKuHrsEyCx yKbsR8/e8Gwkk0QX4YUnHUJZ2I6nTaDR8Xhc4715bt0lWIycnRpXC47w4/4/jq6ezVu8Yw 6xN1xX4BJorH0XuiccjXuko0fPSrYh0= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-99-MU81NohkMrC9ScSVlfdo7A-1; Wed, 26 Aug 2026 14:18:44 -0400 X-MC-Unique: MU81NohkMrC9ScSVlfdo7A-1 X-Mimecast-MFC-AGG-ID: MU81NohkMrC9ScSVlfdo7A_1787768322 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5AB521955E97; Wed, 26 Aug 2026 18:18:41 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.22.88.47]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 330271955F0B; Wed, 26 Aug 2026 18:18:38 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells To: Jens Axboe cc: dhowells@redhat.com, Keith Busch , Hannes Reinecke , Christoph Hellwig , Alexander Viro , Paulo Alcantara , netfs@lists.linux.dev, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] block: Fix start and length check added to iov_iter_extract_bvecs() Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1819785.1787768317.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Wed, 26 Aug 2026 19:18:37 +0100 Message-ID: <1819786.1787768317@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Commit 14b007e17881 added an address check using iter_iov_addr() and a length check using iter_iov_len() to iov_iter_extract_bvecs(), but these cannot be used so and are unsafe in this circumstance as the functions hav= e hardwired assumptions about the iterator type. They should only be used with ITER_UBUF or ITER_IOVEC-type iterators; they should not be used with ITER_BVEC, ITER_KVEC, ITER_FOLIOQ, ITER_XARRAY or ITER_DISCARD iterators. This change proved to be a problem for cachefiles as an iterator of type ITER_FOLIOQ is passed and iter_iov_addr() and iter_iov_len() both malfunction because iter->__iov in iter_iov() is not pointing to an iovec array. Fix this by using iov_iter_alignment() instead. Fixes: 14b007e17881 ("block: validate user space vectors during extraction= ") cc: Keith Busch cc: Jens Axboe cc: Hannes Reinecke cc: Christoph Hellwig cc: Alexander Viro cc: Paulo Alcantara cc: netfs@lists.linux.dev cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org --- diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 6665372ecf71..6df716e19247 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1921,15 +1921,19 @@ ssize_t iov_iter_extract_bvecs(struct iov_iter *it= er, struct bio_vec *bv, unsigned short max_vecs, unsigned mem_align_mask, iov_iter_extraction_t extraction_flags) { - unsigned long start =3D (unsigned long)iter_iov_addr(iter); unsigned short entries_left =3D max_vecs - *nr_vecs; unsigned short nr_pages, i =3D 0; size_t left, offset, len; struct page **pages; ssize_t size; = - if ((start | iter_iov_len(iter)) & mem_align_mask) + if (iov_iter_alignment(iter) & mem_align_mask) { + pr_warn("%u %zx %x\n", + iter->iter_type, + iov_iter_alignment(iter), + mem_align_mask); return -EINVAL; + } = /* * Move page array up in the allocated memory for the bio vecs as far as