From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E688A33B6CC; Tue, 12 May 2026 17:57:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778608660; cv=none; b=UpS7cqKiixhExKY+MxAfHuV61ctg9sEOmHKdOm/0Oq7STIN8R8NnVnDKMhuY8s0xGHsTkRTcvYt8X14lfTn1pyum0ywAJQhfTdC5DnZJsjK9H456FmlPe/qidB8j32aCWvKf2aJ0izEmDQ7WqHAUChZdIWXOtRZzmXgLv1b2uvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778608660; c=relaxed/simple; bh=DMFqJuiAPaaXXVWVZQKldhYogYVEAA0LHjIe68MOPL4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u6prykuSKqHq7TCcYVWzrm3R5CKj+2dVW18+VKZmMoAbv6VfiGxVQ9kHdfCnkChY5aG1wwr/djNCZNIvcfsJ1q4TBEkTt/LNs7Y8U1DpvZicnxrY7ocILSvGggY2ARkUiv0Y3vRC9MC7NjojlL5OxLUVcjFrbYxaG92H2mb4cPQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=uBlzS2jw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="uBlzS2jw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C62EC2BCB0; Tue, 12 May 2026 17:57:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1778608659; bh=DMFqJuiAPaaXXVWVZQKldhYogYVEAA0LHjIe68MOPL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uBlzS2jwixeo/kppIOdSWsD/XQYF+vboCAhUkLIgbPXxpcaiq2ataFDHl4eMvZB8e 9YUkfMAPs+LRItvxqNkuV95IZDdN7LITl/AhftoP+i3LteO8XAok/TEBW32zSOo0Lb ovinCJkTfHq/9w+GxWE6P0YuceU3NfUez5M1/pZg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Christian A. Ehrhardt" , David Howells , David Gow , Kees Cook , Petr Mladek , Andrew Morton Subject: [PATCH 6.18 163/270] lib/scatterlist: fix temp buffer in extract_user_to_sg() Date: Tue, 12 May 2026 19:39:24 +0200 Message-ID: <20260512173941.879074897@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260512173938.452574370@linuxfoundation.org> References: <20260512173938.452574370@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian A. Ehrhardt commit 118cf3f55975352ac357fb194405031458186819 upstream. Instead of allocating a temporary buffer for extracted user pages extract_user_to_sg() uses the end of the to be filled scatterlist as a temporary buffer. Fix the calculation of the start address if the scatterlist already contains elements. The unused space starts at sgtable->sgl + sgtable->nents not directly at sgtable->nents and the temporary buffer is placed at the end of this unused space. A subsequent commit will add kunit test cases that demonstrate that the patch is necessary. Pointed out by sashiko.dev on a previous iteration of this series. Link: https://lkml.kernel.org/r/20260326214905.818170-3-lk@c--e.de Fixes: 018584697533 ("netfs: Add a function to extract an iterator into a scatterlist") Signed-off-by: Christian A. Ehrhardt Cc: David Howells Cc: David Gow Cc: Kees Cook Cc: Petr Mladek Cc: [v6.5+] Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- lib/scatterlist.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -1099,8 +1099,7 @@ static ssize_t extract_user_to_sg(struct size_t len, off; /* We decant the page list into the tail of the scatterlist */ - pages = (void *)sgtable->sgl + - array_size(sg_max, sizeof(struct scatterlist)); + pages = (void *)sg + array_size(sg_max, sizeof(struct scatterlist)); pages -= sg_max; do {