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 E90AF28A1F1; Wed, 23 Apr 2025 15:09:17 +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=1745420958; cv=none; b=NTiPL7DMwu5XfPhSqRom/5nQ89G/drs0PtU9Rqiuk+nu8ptIK2E0ctJUhEUP+uZFi7NTNSieIe41/6aIVJ7IVdUCkKDn1ZBsNAf7ve2Y5qFc83sW40QYmcuOeFssLrX2VGNU3U61ELl4goiS1ruZ1kXyip+nYAVffz6KVlLP0m8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745420958; c=relaxed/simple; bh=0KSJMyjxZrbq1DpLzPTzhyr5Jh+TvUKKDx09ekXXkyg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qL6aIGWTkDHKcoCyOzlu7JSG/DBcO7agosRYYO7aPJnWE4V19oPaVxo4wsftddQUxLbfhrgPnYfdN23NYgfgaqtz7U9Lf7LKvZVkZxpoNK7g/IJwe5jDNpU3lNhfyVLPi/nM2+LWuSmRIonlokEWsP9vkPd6T4B8FBZ28FleDFY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VYxDf+RF; 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="VYxDf+RF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A4F1C4CEE2; Wed, 23 Apr 2025 15:09:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745420957; bh=0KSJMyjxZrbq1DpLzPTzhyr5Jh+TvUKKDx09ekXXkyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VYxDf+RF2DhPpfbmME7SBDvhPxF9EmcQxv69RXRNle3oHepbjKyY8mJizRlYLb3ib swFIHNZr/bBUJ5zNh9DJgC47J/A3cuqh/w0LiGROHMA3+U4vpsTrHRO/U7Y0e/JwEp L9WTlWg2hy+9yXGVQHrC3aACFV2W6t4WofwItvAk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Baoquan He , Oscar Salvador , David Hildenbrand , Andreas Gruenbacher , "Yanjun.Zhu" , Andrew Morton Subject: [PATCH 6.14 139/241] mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable() Date: Wed, 23 Apr 2025 16:43:23 +0200 Message-ID: <20250423142626.237969108@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250423142620.525425242@linuxfoundation.org> References: <20250423142620.525425242@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Baoquan He commit 8c03ebd7cdc06bd0d2fecb4d1a609ef1dbb7d0aa upstream. Not like fault_in_readable() or fault_in_writeable(), in fault_in_safe_writeable() local variable 'start' is increased page by page to loop till the whole address range is handled. However, it mistakenly calculates the size of the handled range with 'uaddr - start'. Fix it here. Andreas said: : In gfs2, fault_in_iov_iter_writeable() is used in : gfs2_file_direct_read() and gfs2_file_read_iter(), so this potentially : affects buffered as well as direct reads. This bug could cause those : gfs2 functions to spin in a loop. Link: https://lkml.kernel.org/r/20250410035717.473207-1-bhe@redhat.com Link: https://lkml.kernel.org/r/20250410035717.473207-2-bhe@redhat.com Signed-off-by: Baoquan He Fixes: fe673d3f5bf1 ("mm: gup: make fault_in_safe_writeable() use fixup_user_fault()") Reviewed-by: Oscar Salvador Acked-by: David Hildenbrand Cc: Andreas Gruenbacher Cc: Yanjun.Zhu Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/gup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/gup.c +++ b/mm/gup.c @@ -2210,8 +2210,8 @@ size_t fault_in_safe_writeable(const cha } while (start != end); mmap_read_unlock(mm); - if (size > (unsigned long)uaddr - start) - return size - ((unsigned long)uaddr - start); + if (size > start - (unsigned long)uaddr) + return size - (start - (unsigned long)uaddr); return 0; } EXPORT_SYMBOL(fault_in_safe_writeable);