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 13A558484 for ; Wed, 1 Mar 2023 18:10:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90437C433A7; Wed, 1 Mar 2023 18:10:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1677694203; bh=/tqhBr78bcSui9bM1khBVdsrHGX3cKbNcIv3aXYs4sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UN3+PFykBMi6fhsvbFmltYGJpHXttZNFh1WarPNZcdV4na95XHQAlQr50o2Bo8J6l ftAnEGLIHi4uu0ocgOvq0Xb1BHF7teGO+poDNKRWK4SciLF3lAyBuzrRnl1BybPttM vv0QDVVf2cOWnytxjwQAaAaDl3jrle/xG4n2ouq8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Storm Dragon , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Linus Torvalds Subject: [PATCH 5.10 11/19] vc_screen: dont clobber return value in vcs_read Date: Wed, 1 Mar 2023 19:08:40 +0100 Message-Id: <20230301180652.795627238@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230301180652.316428563@linuxfoundation.org> References: <20230301180652.316428563@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Thomas Weißschuh commit ae3419fbac845b4d3f3a9fae4cc80c68d82cdf6e upstream. Commit 226fae124b2d ("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: Storm Dragon Link: https://lore.kernel.org/lkml/Y%2FKS6vdql2pIsCiI@hotmail.com/ Fixes: 226fae124b2d ("vc_screen: move load of struct vc_data pointer in vcs_read() to avoid UAF") Signed-off-by: Thomas Weißschuh Link: https://lore.kernel.org/lkml/64981d94-d00c-4b31-9063-43ad0a384bde@t-8ch.de/ Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- drivers/tty/vt/vc_screen.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/drivers/tty/vt/vc_screen.c +++ b/drivers/tty/vt/vc_screen.c @@ -403,10 +403,11 @@ vcs_read(struct file *file, char __user unsigned int this_round, skip = 0; int size; - 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