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 659C138FB0; Tue, 29 Apr 2025 17:13:36 +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=1745946816; cv=none; b=i4E1sgc9DzxuRIOsgmm/rNhe8zPkFneDYhY/h2YTico9xksGH9SqfJrjkksBtjHhfu9gJqYeJKbsguZBEnnNz2AnV9oLNjGQ5t55OYq3FoOAV9frQRfPQXSlOyRVGZ/hy1KCLx44/z0r5m8xXpCAtXebuHlEkKi6RreMK5PkK88= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745946816; c=relaxed/simple; bh=gQxi7YzQMxeTS/3eDTH2NYqrH0192rY4+nLi/EOIqUA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n8eTIBZ7ldlFbepOqJdd4IPszwPk0Ylc/0yYDr909qpMm4qI5pFHsQnJIDDh5zeeH88igy8MFAw0EPatmVnzZUsFBhvO/qa+7x9aeJed/+UK6al/+PeqTmyF21CWXPPbucPpmHmRaG3LZGhvvTcCj6Et15moRRdRGQsIfte0yyA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=L6f5GKkp; 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="L6f5GKkp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E89B3C4CEE3; Tue, 29 Apr 2025 17:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745946816; bh=gQxi7YzQMxeTS/3eDTH2NYqrH0192rY4+nLi/EOIqUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L6f5GKkpxQvO8CBs18YK2hVmdlIFETZK6z6zMlAIpsA11i2kNSd8VkHEzW2Zl48hr oehaDHbqEsZncSg+hj6DqTyVC4CQdoNaraYLXbcQKli2bGOVTHMOaoxmfFRn7SZ/3A PXceoMErUYQWn1Ty1+hCEoy4Z7OMaRx06Ejok8gg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, T Pratham , Robert Jarzmik , Jens Axboe , Kamlesh Gurudasani , Praneeth Bajjuri , Vignesh Raghavendra , Andrew Morton Subject: [PATCH 5.10 079/286] lib: scatterlist: fix sg_split_phys to preserve original scatterlist offsets Date: Tue, 29 Apr 2025 18:39:43 +0200 Message-ID: <20250429161111.098792675@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161107.848008295@linuxfoundation.org> References: <20250429161107.848008295@linuxfoundation.org> User-Agent: quilt/0.68 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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: T Pratham commit 8b46fdaea819a679da176b879e7b0674a1161a5e upstream. The split_sg_phys function was incorrectly setting the offsets of all scatterlist entries (except the first) to 0. Only the first scatterlist entry's offset and length needs to be modified to account for the skip. Setting the rest entries' offsets to 0 could lead to incorrect data access. I am using this function in a crypto driver that I'm currently developing (not yet sent to mailing list). During testing, it was observed that the output scatterlists (except the first one) contained incorrect garbage data. I narrowed this issue down to the call of sg_split(). Upon debugging inside this function, I found that this resetting of offset is the cause of the problem, causing the subsequent scatterlists to point to incorrect memory locations in a page. By removing this code, I am obtaining expected data in all the split output scatterlists. Thus, this was indeed causing observable runtime effects! This patch removes the offending code, ensuring that the page offsets in the input scatterlist are preserved in the output scatterlist. Link: https://lkml.kernel.org/r/20250319111437.1969903-1-t-pratham@ti.com Fixes: f8bcbe62acd0 ("lib: scatterlist: add sg splitting function") Signed-off-by: T Pratham Cc: Robert Jarzmik Cc: Jens Axboe Cc: Kamlesh Gurudasani Cc: Praneeth Bajjuri Cc: Vignesh Raghavendra Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- lib/sg_split.c | 2 -- 1 file changed, 2 deletions(-) --- a/lib/sg_split.c +++ b/lib/sg_split.c @@ -88,8 +88,6 @@ static void sg_split_phys(struct sg_spli if (!j) { out_sg->offset += split->skip_sg0; out_sg->length -= split->skip_sg0; - } else { - out_sg->offset = 0; } sg_dma_address(out_sg) = 0; sg_dma_len(out_sg) = 0;