Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp290343rwn; Thu, 8 Sep 2022 01:25:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR5fm7KgnlBGKdKDEjzVkoLRAiMhg//pJySD3XEdoBizriBYMFjhER29MNqXBQX1PnkgkY3F X-Received: by 2002:a17:90b:1d02:b0:1fe:36a:6e01 with SMTP id on2-20020a17090b1d0200b001fe036a6e01mr2975523pjb.102.1662625526375; Thu, 08 Sep 2022 01:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662625526; cv=none; d=google.com; s=arc-20160816; b=I9unmgmy7vJF48NcQ3lah2CHWrAr9lzoWufqzq2X7awL6rzyr2pX4e6KHAGSDUSnQ0 oDdxnCQZGAZuKENcFo1M3HFBxDvL+SRXQU1+JxTRoVFbeb1Mw/9IIBttQ+Xj9jd43f5Q vEhPvRhP9kvwAZ/RP8nw73y2oRKIpKQ+FXQW7sRcdnCaYw7a7AQmmeaoi3BksFSx7F/0 malP6cHLFDwClb5Jm7jVnhwEywc9Y674sPzmBOeAhwfzX/COFJM0uDwjBNqS88yngHUo rO68fhkei3vFQWNRHXp3hc+59AC588Ey5sOzMIJxHDo52OadAhD1iHaJyPV5UCx+a7WJ GW5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=rerb8dBjaJIj684oB5luqPScyX3HGs/aBYa5L7pt+5A=; b=yhJf4uo9e5W0rr6vX+0YXZAieiLRQ1otDZrbf781HX2H7tnhOLyQAMlBxPibWQG58r sKKqPOVZKJvq2T0a4L90r5Avqv0mYZ7mM9WHjabEfb8H76oQ+D4fkrbuiXFuwEYr3wye yTWWO6zHRwWsAIUeduYNhaeiBkBw31Cc5/0QWnWnBgjHFHT8m4bXz/bEweX0seNlcxh9 t5COJFqyRRbbLRZisRiSUb5TncIDS3r9LubDJG4ffQeWKugeIGd2b8h3Ds8fEzpb3CxL E8BKST+Q/s9Ino/010zVbWgdzdFcsRbweo2MQyyhV77GDfpQXbbXp5ZbRquAyCSm1pQu EIUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LPQ1KfrG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x12-20020a170902ec8c00b0016e5ab112c9si19000292plg.179.2022.09.08.01.25.11; Thu, 08 Sep 2022 01:25:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LPQ1KfrG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231338AbiIHIQ1 (ORCPT + 99 others); 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> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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