Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1193209pxb; Wed, 10 Feb 2021 02:24:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJycshmHq+ok3eqWiHYTThk3cPmbibJwT7XENmHCtMsyfrYkUBrz/60H3pWKlqOMiMBS1oDD X-Received: by 2002:a50:f318:: with SMTP id p24mr2482449edm.13.1612952654254; Wed, 10 Feb 2021 02:24:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612952654; cv=none; d=google.com; s=arc-20160816; b=IP6rTIbP6r2Cn66cdYsduFI0wVhFaK0RfSHb6ZEvJtM03iKKVgXYuKohWJWgVjhLYJ Ck1HqLV4cdeVypuQ3XwPhl37HObQZtLmnXJjvte2UbnSbxX6zRh247q1PzX+Z3Y1y+ty Al2f0xxZSGsl70DiDzbgRcunPSHAdkUxhF13i+uOMvGcPjWC9rbIaUMx1QrJb9Hs9DQq GBkm91zpJ3s1PnRu7B1YbigRYPr8aPd9vJpeA/H/nFaA2kn5s66weGmvGaTblYKo1tA2 o0+IksZiCMI8GzwaaK3OXd5bxyXWXtq68aj35NQSI4H88t6nOylZMwWajbpQGJcP2lcC rLrA== 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=ontaDL3XvHswihYEf1iBGmLwX9Q6quQQDImWbCzSgjA=; b=nG+wsyQB3jrcZjD+n9Cz2ban7nJuYGS8WxMbXJtboAFUbPMzhFX6vEx/BhhqHbZZIU nd5t6UrD+2itLIYk22a12YHco58muosCfPYo2dB7hPmfffAnYv2IL0yjyhECV09HqmV5 uQiaiHYMhM093YHcmD+SQ71Zl/AXTfAs+MJr9MwC+L6TO+yLFEE6gHDB6jeY5XGkueqU gtb6v1h+hHVzIjbfgGat17jUsdmhbbHHy5W0nYUj3F07qKQeMBf+IEg/u9+36vTJqo3U VPt1ajLnCFAGCmnD+9FixOR3P04wi4c6LBPeMnxXd0FOdV0W9p0pi9nC13AEATkEsgOJ cp6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=W+ZtDtES; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m9si1070857edj.103.2021.02.10.02.23.50; Wed, 10 Feb 2021 02:24:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=W+ZtDtES; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231235AbhBJKXB (ORCPT + 99 others); Wed, 10 Feb 2021 05:23:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49137 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230493AbhBJKKC (ORCPT ); Wed, 10 Feb 2021 05:10:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612951710; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ontaDL3XvHswihYEf1iBGmLwX9Q6quQQDImWbCzSgjA=; b=W+ZtDtESJ/g+SlT2S3JO4cKESIlpec5YEZUPEMZQLVZj/x49m/Uw9OOERlOjXgP+MdzPmb gJLAXq0VJkgkfeucGWFnrGIgQDAc6gsaaVXj0XnvJWv9RZa4ZdE9jfV9mBRRD9uAO56hUA iULKrDU0qUPNbqZlv3Rg6VAg6FjquLM= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-226-XDTVWMfpOZC1p8INQTxVWA-1; Wed, 10 Feb 2021 05:08:26 -0500 X-MC-Unique: XDTVWMfpOZC1p8INQTxVWA-1 Received: by mail-ej1-f71.google.com with SMTP id p1so2155982ejo.4 for ; Wed, 10 Feb 2021 02:08:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=ontaDL3XvHswihYEf1iBGmLwX9Q6quQQDImWbCzSgjA=; b=Gi9yAjlu05YDu902HnEvyH7YZhcgu/PqrStBxs9Xg3mNay/syEp6bhH59Hgt4Ff13/ mC+CH2UY3fpw9W+8YKSOduguBbx0Yxl2xO7QcJC3ZJ9o5v5jW3owVcA9bR51Dri4Sjjp G9JuP94iOVOWKMDtC+Pn0TleSZQbprayE+yFfqnQE0YjHhUBtEaonAtjmxzrIChNEJYV 7WkutHm6Ce8e11UdxBsw0uTs6LOEPt++szrY2ss7lZYVSJjAavTfqC4ga8pQbZ2dM1Bd 3OTWdpM3N7UbEawpaGb/w4noZwptQVjdptx3ol1nnHKbYV3IoFxem/1FxKJuPGW2KOWN jriQ== X-Gm-Message-State: AOAM533S1WGGI1QhvVqO0nIbsxWZ60K+vpX2n+jq1clr3/AIzGPWsP8o m+YBhTwMt7nuXdEgACvSCS+q2oN/VQIflruG3Dbr7ubzTgZ5AMJ7e+qLyECBWrH774gNWC1OxJd 6pR+Zjsn9VJlMtvwKjg7OwEPO X-Received: by 2002:a05:6402:702:: with SMTP id w2mr2511041edx.78.1612951705281; Wed, 10 Feb 2021 02:08:25 -0800 (PST) X-Received: by 2002:a05:6402:702:: with SMTP id w2mr2511028edx.78.1612951705069; Wed, 10 Feb 2021 02:08:25 -0800 (PST) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id g9sm777753ejp.55.2021.02.10.02.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 02:08:24 -0800 (PST) Date: Wed, 10 Feb 2021 11:08:21 +0100 From: Stefano Garzarella To: "Michael S. Tsirkin" Cc: Jason Wang , virtualization@lists.linux-foundation.org, Parav Pandit , Eli Cohen , linux-kernel@vger.kernel.org Subject: Re: [PATCH] vdpa/mlx5: fix param validation in mlx5_vdpa_get_config() Message-ID: <20210210100821.aaye2cgmrpwhhzgn@steredhat> References: <20210208161741.104939-1-sgarzare@redhat.com> <20210208133312-mutt-send-email-mst@kernel.org> <20210209042530-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210209042530-mutt-send-email-mst@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 09, 2021 at 04:31:23AM -0500, Michael S. Tsirkin wrote: >On Tue, Feb 09, 2021 at 11:24:03AM +0800, Jason Wang wrote: >> >> On 2021/2/9 上午2:38, Michael S. Tsirkin wrote: >> > On Mon, Feb 08, 2021 at 05:17:41PM +0100, Stefano Garzarella wrote: >> > > It's legal to have 'offset + len' equal to >> > > sizeof(struct virtio_net_config), since 'ndev->config' is a >> > > 'struct virtio_net_config', so we can safely copy its content under >> > > this condition. >> > > >> > > Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices") >> > > Cc: stable@vger.kernel.org >> > > Signed-off-by: Stefano Garzarella >> > > --- >> > > drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +- >> > > 1 file changed, 1 insertion(+), 1 deletion(-) >> > > >> > > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c >> > > index dc88559a8d49..10e9b09932eb 100644 >> > > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c >> > > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c >> > > @@ -1820,7 +1820,7 @@ static void mlx5_vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, >> > > struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); >> > > struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); >> > > - if (offset + len < sizeof(struct virtio_net_config)) >> > > + if (offset + len <= sizeof(struct virtio_net_config)) >> > > memcpy(buf, (u8 *)&ndev->config + offset, len); >> > > } >> > Actually first I am not sure we need these checks at all. >> > vhost_vdpa_config_validate already validates the values, right? >> >> >> I think they're working at different levels. There's no guarantee that >> vhost-vdpa is the driver for this vdpa device. > >In fact, get_config returns void, so userspace can easily get >trash if it passes incorrect parameters by mistake, there is >no way for userspace to find out whether that is the case :( > >Any objections to returning the # of bytes copied, or -1 >on error? Make sense for me, but are we sure we don't break userspace if we return the number of bytes instead of 0 on success? I had a quick look at QEMU and it looks like we consider success if the return value is >= 0, but I need to check further. > >> >> > >> > Second, what will happen when we extend the struct and then >> > run new userspace on an old kernel? Looks like it will just >> > fail right? So what is the plan? >> >> >> In this case, get_config() should match the spec behaviour. That is to say >> the size of config space depends on the feature negotiated. >> >> Thanks > >Yes but spec says config space can be bigger than specified by features: > > Drivers MUST NOT limit structure size and device configuration space size. Instead, drivers SHOULD only > check that device configuration space is large enough to contain the fields necessary for device operation. > So IIUC in the driver we should copy as much as we can. If you agree, I can send an RFC series and we can continue the discussion on it, but I think we should queue this patch for stable branches. Thanks, Stefano