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 7841CECAAD5 for ; Thu, 8 Sep 2022 08:16:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231386AbiIHIQ1 (ORCPT ); Thu, 8 Sep 2022 04:16:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230240AbiIHIQY (ORCPT ); Thu, 8 Sep 2022 04:16:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05A29B7EFB for ; Thu, 8 Sep 2022 01:16:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 87A27B8204C for ; Thu, 8 Sep 2022 08:16:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B13CDC433D6; Thu, 8 Sep 2022 08:16:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662624980; bh=DOujSj518pTDqCW8cJ1ggvFcLqk5w9OFQjxBCzgVe1c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LPQ1KfrGrPpprzueD6oFyqiCYaHKw6DA7Sg33wm6AFOB5TscrMEpK48Qo+SjenSCT uHIaj/RT60pqJH2K66OCY64ARDYtbCNTNFff+Exgf+Bx/BcFRujx61S0dRgSvsBnlx a+PnsviNCT0wuW+tc/NlqIxeOYv0slqO+qWBKGEU= Date: Thu, 8 Sep 2022 10:16:17 +0200 From: Greg KH To: Hangyu Hua Cc: jirislaby@kernel.org, changlianzhi@uniontech.com, dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tty: vt: add a bounds checking in vt_do_kdgkb_ioctl() Message-ID: References: <20220908075403.27930-1-hbh25y@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220908075403.27930-1-hbh25y@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 08, 2022 at 03:54:03PM +0800, Hangyu Hua wrote: > As array_index_nospec's comments indicate,a bounds checking need to add > before calling array_index_nospec. > > Signed-off-by: Hangyu Hua > --- > drivers/tty/vt/keyboard.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c > index be8313cdbac3..b9845455df79 100644 > --- a/drivers/tty/vt/keyboard.c > +++ b/drivers/tty/vt/keyboard.c > @@ -2067,6 +2067,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm) > if (get_user(kb_func, &user_kdgkb->kb_func)) > return -EFAULT; > > + if (kb_func >= MAX_NR_FUNC) > + return -EFAULT; Wrong error to return, only ever return that error if you have a memory fault from copy_to/from_user(). But even then, how can kb_func ever be greater than MAX_NR_FUNC? And what is wrong with it being MAX_NR_FUNC? > + > kb_func = array_index_nospec(kb_func, MAX_NR_FUNC); Maybe we really don't need this at all, right? thanks, greg k-h