Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2237699rwb; Thu, 19 Jan 2023 23:36:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXuWYaMT+cHj+6R0hF8tgL00DOR4qTXCyFh+B7xAJ9tTFv+p/8osSLqwKrCjk1QtsRgWE30V X-Received: by 2002:a17:906:6814:b0:870:ef77:e186 with SMTP id k20-20020a170906681400b00870ef77e186mr13474620ejr.49.1674200167033; Thu, 19 Jan 2023 23:36:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674200167; cv=none; d=google.com; s=arc-20160816; b=RfPY4SdPc4YhhuioV84Zg8QWUq9jz73w7qbzWH5LxHYqWgUcip7gzh5QmQnDnPXl74 oHar9ySmDL1RFmSIxh0V/nTzfkUSE2EXQXJTT3tDQI1B2caDvXib33TmBm+l+KjHLk8T y/7smKY0F+Etav8/PtrQGuh+AZj2A/0jhjvgraQexM45oQZ0GsfO9bKaB4gpvJOZiIqL IDMuAIyGDZ3Bf4QNHX2vXJaGnl0Aq/TEnAyFhDc17EPmMoi6SXynaiUCLUBZfQ9Wzo8a rAE5cFRPl1pkefZINkvkAL4EFMGe0ZqJZvshuKlrPg+AmgGUa0ApHAu44e7G1PjB+go3 yF1w== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Fv08sOoalhTRL5+BSVZjOFGoOyfoomhzEEKhe4AlZI4=; b=moC566N9gZtxxl+HE1d4QVRTHO0L8lX1CBkg4Seu3x4yj+ezFdILAGD1UyOUqQkVuD zC9Sw5OJ0/xp1Tvve8gIwWaqFIqUIdEzR+aQAFldD3dXlhqpYo1zXHA86zMVCv0XuTT3 7NFHxnJzCnwVssT8h2gOixzUfeZvxOqBkU/Wn/lI1d3EroXx/EMYbEzc+3jGJEByh34r rTj5+5pPJtJru92Pco0AdwrQciakQN3aZPvQZqq1kIDIQjMhDMsGLShTXRWOa5pXt7aJ UsTSHGH8eyu/hIJ6B9BlQBrDqzvao0bwS6eLBLiW3sgkqvKG7zkYTp594Z8FciCk0sJo BfTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="N5/cD8+5"; 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 qf17-20020a1709077f1100b007c17420be5bsi17181621ejc.178.2023.01.19.23.35.55; Thu, 19 Jan 2023 23:36:07 -0800 (PST) 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="N5/cD8+5"; 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 S230017AbjATHPX (ORCPT + 47 others); Fri, 20 Jan 2023 02:15:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229764AbjATHPW (ORCPT ); Fri, 20 Jan 2023 02:15:22 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 425A84347C for ; Thu, 19 Jan 2023 23:15:21 -0800 (PST) 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 E45D6B81A74 for ; Fri, 20 Jan 2023 07:15:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0E37C433EF; Fri, 20 Jan 2023 07:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1674198918; bh=dGwXf0BmH8FB3+W1jC+RE4rVTDz4Q5BheAiK4UorBxw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=N5/cD8+5/Qo1ZOqM50106fjf6hDtXPzyqTlRT7Fr7HckbdfcicUOztJa/efgae8nu sTND8M5DFHXarP+78nsVn8FvQn+cD0s0mZOtKkfTY8IRoTvsR24i1cNX+RFwHm886+ rqlffC+0G3kHaQCIpDod0CZRivBH2YfmpVimDOaA= Date: Fri, 20 Jan 2023 08:15:15 +0100 From: Greg Kroah-Hartman To: Alexander Shishkin Cc: mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, elena.reshetova@intel.com, kirill.shutemov@linux.intel.com, Andi Kleen , Amit Shah , Arnd Bergmann Subject: Re: [PATCH v1 2/6] virtio console: Harden port adding Message-ID: References: <20230119135721.83345-1-alexander.shishkin@linux.intel.com> <20230119135721.83345-3-alexander.shishkin@linux.intel.com> <87ilh2quto.fsf@ubik.fi.intel.com> <87a62eqo4h.fsf@ubik.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a62eqo4h.fsf@ubik.fi.intel.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 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, Jan 19, 2023 at 10:13:18PM +0200, Alexander Shishkin wrote: > Greg Kroah-Hartman writes: > > > Then you need to copy it out once, and then only deal with the local > > copy. Otherwise you have an incomplete snapshot. > > Ok, would you be partial to something like this: > > >From 1bc9bb84004154376c2a0cf643d53257da6d1cd7 Mon Sep 17 00:00:00 2001 > From: Alexander Shishkin > Date: Thu, 19 Jan 2023 21:59:02 +0200 > Subject: [PATCH] virtio console: Keep a local copy of the control structure > > When handling control messages, instead of peeking at the device memory > to obtain bits of the control structure, take a snapshot of it once and > use it instead, to prevent it from changing under us. This avoids races > between port id validation and control event decoding, which can lead > to, for example, a NULL dereference in port removal of a nonexistent > port. > > The control structure is small enough (8 bytes) that it can be cached > directly on the stack. > > Signed-off-by: Alexander Shishkin > Cc: Greg Kroah-Hartman > Cc: Arnd Bergmann > Cc: Amit Shah > --- > drivers/char/virtio_console.c | 29 +++++++++++++++-------------- > 1 file changed, 15 insertions(+), 14 deletions(-) Yes, this looks much better, thanks! Reviewed-by: Greg Kroah-Hartman