Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp337527rwn; Thu, 8 Sep 2022 02:21:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR7aR07zTC9QxtOFZHeZVcmeQgG1eff4Bt3ff02H8wWYqV4mBy8hJDUeEHGuLk97uBEzuwf7 X-Received: by 2002:a17:902:a384:b0:173:4085:23d8 with SMTP id x4-20020a170902a38400b00173408523d8mr8025603pla.143.1662628865171; Thu, 08 Sep 2022 02:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662628865; cv=none; d=google.com; s=arc-20160816; b=XFN4Boxi4SV7J5EjeDziHWfv1M1+flt06BFFOpevJWmBIPw5ipvRqhVtj5uWyR5OKe VDRcY7wB1bXNsQaIXrqDFDsYPTuE3UZLFue38bQOv5X6PujDsJwOd0L+FprDJNYJc2EU 40uZRLyvIqiFxA3mqy4iQqPrFEWpsT0VkEoimfgQcLq0JpLAo/F+Qj+BDkoc/99/6tjX lSMCgUailWzlPlmuptEYHsRgp7uKcw5ZJ1i1DFTwaO9PQPFfssblOEIrnpQfL0uv03wZ jBAN4BIK2Zfh2lJvOgeCHmZ1REKfgly+40mLw1sXYd/shcrpQSsiag/C/G0ZE2MxkHa1 7aQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=Bj+mLV6GrBWexFrxYIG1e6IyShZ1xzdoaItMhP88h9U=; b=Twh9L0m/Zu7tgIaFrxC1W+8uVBwoaYLQSLFGQjsublFe2yduCVnWsd3U2DIDSxgArD EgAGccwSx9cJXmFBW4DP4CCpa/QTzCcst7tekfrCa5X7qYHf3Lm7JiLmwBSLW+v5yCRN xQcOUbQQJY81CN57E2wDgCBVa7eOCoFxHFRUsti/Xq8xyXoSGhdSZpzK98IAQlAsUAuJ gc8Q/E5UYxDFOpMkITycKLrCJSlFutN0ToOaM1EpyuoC8PPhz/MnogAPXAieFHYEBpxi 1FavfkwB+FQ5ldd3hmx4FM9yzEwLks1QRmVxRBtk3UBIwB1VmrImZB9sTfOtsmpzOJnK j5sw== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v16-20020a62a510000000b0053a9fee3b20si18513927pfm.159.2022.09.08.02.20.52; Thu, 08 Sep 2022 02:21:05 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231358AbiIHIKm (ORCPT + 99 others); Thu, 8 Sep 2022 04:10:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231460AbiIHIK0 (ORCPT ); Thu, 8 Sep 2022 04:10:26 -0400 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1776171BF9 for ; Thu, 8 Sep 2022 01:10:16 -0700 (PDT) Received: by mail-ej1-f51.google.com with SMTP id bj12so36134137ejb.13 for ; Thu, 08 Sep 2022 01:10:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=Bj+mLV6GrBWexFrxYIG1e6IyShZ1xzdoaItMhP88h9U=; b=DYD9H3kNrMMX1v9aGFkGmSJPdsk6yOOj902oYmmJTRFDo8Zgz0C+fXTLI+cVbBneaW W5HRO4GJUA42yo3BG3yqmWE33xPhkHRRyuRJvOU0SAAdRzJ8aEkm8oY71WoeVQ6rZNP9 8xLHgyDa7KgTEL+MbBPt3gw6lRNErmtmjB9z8eeTenUWbX/2qMwpwOpYI9Ucq3aLG3TD Wv6JbU3cKcsPBSYTa35EfNYrc3667+DnZueyvVexl+T9/SPYWRuqAqHWuUlOdVaFR3+Y 1gdupqjpyWi3FdTDxBNJo+3la3WJKO2qN65K0nzuRXTzipzkVwvsvKtwJcVe5LkYEeNd pgSQ== X-Gm-Message-State: ACgBeo0HQ7DF61FiQ8ZKazOvDNv6/mD9Gc8mfAM3O7Ami13e4Gt3Bpfu F7VqkT+RfbGxTzoTUqWtyNtCEoeO630= X-Received: by 2002:a17:907:2c44:b0:770:8623:66c4 with SMTP id hf4-20020a1709072c4400b00770862366c4mr4364644ejc.3.1662624614380; Thu, 08 Sep 2022 01:10:14 -0700 (PDT) Received: from [192.168.1.49] (185-219-167-24-static.vivo.cz. [185.219.167.24]) by smtp.gmail.com with ESMTPSA id b5-20020aa7c6c5000000b00450206d9dfbsm783233eds.84.2022.09.08.01.10.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Sep 2022 01:10:13 -0700 (PDT) Message-ID: <6236da54-c651-9dc7-f5ce-824be96b3e9d@kernel.org> Date: Thu, 8 Sep 2022 10:10:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH] tty: vt: add a bounds checking in vt_do_kdgkb_ioctl() To: Hangyu Hua , gregkh@linuxfoundation.org, changlianzhi@uniontech.com, dmitry.torokhov@gmail.com Cc: linux-kernel@vger.kernel.org References: <20220908075403.27930-1-hbh25y@gmail.com> Content-Language: en-US From: Jiri Slaby In-Reply-To: <20220908075403.27930-1-hbh25y@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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 08. 09. 22, 9:54, 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) kb_func is unsigned char and MAX_NR_FUNC is 256. So this should be eliminated by the compiler anyway. But the check might be a good idea if we ever decide to support more keys. But will/can we? I am not so sure, so adding it right now is kind of superfluous. In any way we'd need to introduce a completely different iterface/ioctls. > + return -EFAULT; EINVAL would be more appropriate, IMO. > + > kb_func = array_index_nospec(kb_func, MAX_NR_FUNC); > > switch (cmd) { thanks, -- js suse labs