Commit cbc7fa2e authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Yi Yang
Browse files

vc_screen: don't clobber return value in vcs_read

stable inclusion
from stable-v4.19.275
commit e534b1ce31679ad447aa07690b5c327c767a6020
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBWVWQ
CVE: CVE-2023-52973

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=e534b1ce31679ad447aa07690b5c327c767a6020



--------------------------------

commit ae3419fb upstream.

Commit 226fae12 ("vc_screen: move load of struct vc_data pointer in
vcs_read() to avoid UAF") moved the call to vcs_vc() into the loop.

While doing this it also moved the unconditional assignment of

	ret = -ENXIO;

This unconditional assignment was valid outside the loop but within it
it clobbers the actual value of ret.

To avoid this only assign "ret = -ENXIO" when actually needed.

[ Also, the 'goto unlock_out" needs to be just a "break", so that it
  does the right thing when it exits on later iterations when partial
  success has happened - Linus ]

Reported-by: default avatarStorm Dragon <stormdragon2976@gmail.com>
Link: https://lore.kernel.org/lkml/Y%2FKS6vdql2pIsCiI@hotmail.com/


Fixes: 226fae12 ("vc_screen: move load of struct vc_data pointer in vcs_read() to avoid UAF")
Signed-off-by: default avatarThomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/lkml/64981d94-d00c-4b31-9063-43ad0a384bde@t-8ch.de/


Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarYi Yang <yiyang13@huawei.com>
parent 5f5619a7
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -266,10 +266,11 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
		ssize_t orig_count;
		long p = pos;

		ret = -ENXIO;
		vc = vcs_vc(inode, &viewed);
		if (!vc)
			goto unlock_out;
		if (!vc) {
			ret = -ENXIO;
			break;
		}

		/* Check whether we are above size each round,
		 * as copy_to_user at the end of this loop