Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4483393pxb; Mon, 21 Feb 2022 22:56:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcGVUTf+LVTl9ZMQECcB/iQUcV2SQKqWeLime+nDo3wtMbUnok6EPGe6SQVTjAG+6ZtNs1 X-Received: by 2002:a05:6a00:984:b0:4e1:5e1b:1e9b with SMTP id u4-20020a056a00098400b004e15e1b1e9bmr23292719pfg.71.1645512984927; Mon, 21 Feb 2022 22:56:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645512984; cv=none; d=google.com; s=arc-20160816; b=OYTqIJQefFUmEF4u/DEpjx+6FynsR8wgXF0wE658M62LDQ7fcMDzShhvqQpzLdloDg iluWSbd65SAFePZsMO+mbt0hu1mcTaD64PZSbBonJnWXtfqRTIzDZu/YqWNG2PGXd4ew LhFyaJxHQ38yEGvOIQcZzrUkXqXu+OIAc2K4qqiVWqJ+Lg7yM7hQ5x8o/syYEbV6EhT/ U+YSNRVVl87/LZrPw72YyTrPH6iagYuoX+q+RueIatzcwb9KKeI/tFM0jumexffUGOlz gIGvJx1RDG4OsGjkXOufc1W3vQ3jdvnBNIJPyt8o69MDlOzAyqLv3cVgrUiwCCwp0isZ gN2w== 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 :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=jQN5YzYRBcWg2FYiwHk5tUXo/roFvACWKbFSOX5eYcc=; b=W1lL46HVssq6o75Q/OVLDhKKzpVTVx1stYSm9yXszEdN3vefpi43czrIUOjwQlgXY8 F+bcPZdawmk15kb+riQhnt2wMjcRZJwJyf27S5vJ+jFe1/61AFcx1wkR7ZmDcSRAQMSJ dQnduMHAFIeeraoU8ewsJ49+VDcqEV/elkyr72pMTRtFwHNH5JdgMCkH9Ti/ciPllU4o VODcVReV0LHurY8EVoawppbDasBNRai+EFoe7Fh1yWQBx/9Y5ED1d4/FwJbgI24/3byv ZcG0TRNkEpo/NZoSBOY2mj6ydCaYtYcWI5Pumkp/MRVaODQPLy3fMK9GnWa1kADZtfNy kLfw== 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:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x10si19044731pge.572.2022.02.21.22.56.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 22:56:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1D9DF111DE2; Mon, 21 Feb 2022 22:56:23 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230316AbiBVG4p (ORCPT + 99 others); Tue, 22 Feb 2022 01:56:45 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:40750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230366AbiBVG4l (ORCPT ); Tue, 22 Feb 2022 01:56:41 -0500 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87DB8111DDE for ; Mon, 21 Feb 2022 22:56:16 -0800 (PST) Received: by mail-ed1-f41.google.com with SMTP id w3so34524179edu.8 for ; Mon, 21 Feb 2022 22:56:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=jQN5YzYRBcWg2FYiwHk5tUXo/roFvACWKbFSOX5eYcc=; b=iQj+0CxSiSC3e4CZTsrswjXbWs9TgMN1/Vu6SGjHBMdxsDmdeKIYpSrfsdLlaLXAqV 4gDdVof5f1ML4M91fBbjXfGIEV85PLbFvlEZySVOFjAQp21Hl27HeQ5AFEhPEPeixcXi WpQIyUdEagWwQwb3TrODOb6oDpUrELg+Rw9yo/VANBxPjql6wtTkpQvaKVi4S+fHdIoU s92I1CqJ2/Np6ME/oegbi9gINDEbetrWwRjx/u3x8qTZFsU1kQui9Ck+jBwO+3hXowW5 xcRExot0tMmdxEriWM1XFbsScvxn3BYqpu9309QccGQJGzfiS54cndJ0lDWg/kdH4znc jtyg== X-Gm-Message-State: AOAM5313hGpyCahXZ6+7vehiG6GWAhxO4aOXEOk7MP1ZPEm3/y8P703O DNblVg4DzCX8X+nDgIiftwpXkYO16GQ= X-Received: by 2002:a50:f69c:0:b0:410:8241:580c with SMTP id d28-20020a50f69c000000b004108241580cmr24478799edn.100.1645512975162; Mon, 21 Feb 2022 22:56:15 -0800 (PST) Received: from ?IPV6:2a0b:e7c0:0:107::70f? ([2a0b:e7c0:0:107::70f]) by smtp.gmail.com with ESMTPSA id m28sm5941827ejn.50.2022.02.21.22.56.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Feb 2022 22:56:14 -0800 (PST) Message-ID: Date: Tue, 22 Feb 2022 07:56:13 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH] vt_ioctl: fix potential spectre v1 in VT_DISALLOCATE Content-Language: en-US To: Xiaomeng Tong , gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org References: <20220222035648.17984-1-xiam0nd.tong@gmail.com> From: Jiri Slaby In-Reply-To: <20220222035648.17984-1-xiam0nd.tong@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 22. 02. 22, 4:56, Xiaomeng Tong wrote: > In VT_ACTIVATE an almost identical code path has been patched > with array_index_nospec. In the VT_DISALLOCATE path, the arg is > the user input from a system call argument and lately used as a index > for vc_cons[index].d access, which can be reached through path like > vt_disallocate->vc_busy or vt_disallocate->vc_deallocate. > For consistency both code paths should have the same mitigations > applied. > > Signed-off-by: Xiaomeng Tong > --- > drivers/tty/vt/vt_ioctl.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c > index 580136986..acd53c1c9 100644 > --- a/drivers/tty/vt/vt_ioctl.c > +++ b/drivers/tty/vt/vt_ioctl.c > @@ -898,10 +898,13 @@ int vt_ioctl(struct tty_struct *tty, > if (arg > MAX_NR_CONSOLES) > return -ENXIO; > > - if (arg == 0) > + if (arg == 0) { > vt_disallocate_all(); Could you add a break; here and remove the else branching completely? > - else > - return vt_disallocate(--arg); > + } else { > + --arg; > + arg = array_index_nospec(arg, MAX_NR_CONSOLES); You could simply do: arg = array_index_nospec(arg - 1, MAX_NR_CONSOLES); and remove --arg; completely. > + return vt_disallocate(arg); > + } > break; When you do the above, this break is superfluous. thanks, -- js suse labs