From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AADFAC83F01 for ; Wed, 30 Aug 2023 18:56:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344053AbjH3S4k (ORCPT ); Wed, 30 Aug 2023 14:56:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344010AbjH3R5t (ORCPT ); Wed, 30 Aug 2023 13:57:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAE50BE; Wed, 30 Aug 2023 10:57:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 58FA4620A3; Wed, 30 Aug 2023 17:57:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A395C433C7; Wed, 30 Aug 2023 17:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1693418264; bh=7W67d4uHZx8ajrE+AREOx4IigFIIZor8rqkBDeQvMJ4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OLHkY9OhI80JbtlD7N/Cxgq0zP3p6QW4HGRHg1+n9m0NGjIkyVEk+1mPYO+GNqX7i g/BeVBWxc1FLg/sYMIaRJEau45F73DyIVz0hkHp25+O/zWAJYkRJNXQKvU8wC/f+nZ MkuPE8G86R+nVwdE1Piox6loaLtKj+V83SwrsifQ= Date: Wed, 30 Aug 2023 19:57:41 +0200 From: Greg Kroah-Hartman To: Azeem Shaikh Cc: Jiri Slaby , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Kefeng Wang , Andrew Morton Subject: Re: [PATCH] vt: Fix potential read overflow of kernel memory Message-ID: <2023083035-unpadded-amulet-8c7e@gregkh> References: <20230830160410.3820390-1-azeemshaikh38@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230830160410.3820390-1-azeemshaikh38@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org On Wed, Aug 30, 2023 at 04:04:10PM +0000, Azeem Shaikh wrote: > strlcpy() reads the entire source buffer first. > This read may exceed the destination size limit if > a source string is not NUL-terminated [1]. But that's not the case here, right? So your "potential read overflow" isn't relevant here. > The copy_to_user() call uses @len returned from strlcpy() directly > without checking its value. This could potentially lead to read > overflow. But can it? How? Those are all hard-coded strings, in the kernel source, there is no potential overflow here. And you know the buffer size is correct as well. So why even check? > In an effort to remove strlcpy() completely [2], replace > strlcpy() here with strscpy(). > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy > [2] https://github.com/KSPP/linux/issues/89 > > Signed-off-by: Azeem Shaikh > --- > drivers/tty/vt/keyboard.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c > index 358f216c6cd6..15359c328a23 100644 > --- a/drivers/tty/vt/keyboard.c > +++ b/drivers/tty/vt/keyboard.c > @@ -2079,12 +2079,15 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm) > return -ENOMEM; > > spin_lock_irqsave(&func_buf_lock, flags); > - len = strlcpy(kbs, func_table[kb_func] ? : "", len); > + len = strscpy(kbs, func_table[kb_func] ? : "", len); > spin_unlock_irqrestore(&func_buf_lock, flags); > > + if (len < 0) { > + ret = -EFAULT; > + break; > + } Don't check for impossible things please. thanks, greg k-h