Message ID | e2361611-e8e3-4c6a-9f71-30e81a65f793@moroto.mountain |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-85458-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3514769dyb; Wed, 28 Feb 2024 10:03:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVBSAQBqWyuD5JKwXR1n4+kWtJ6B0+uaD1I5H7eAbBdKU2XSt9HFEgn/83eTEAO8CJhovhaKKr3HabhiQkI08LOeQAKVw== X-Google-Smtp-Source: AGHT+IEjVy9TmVjLzMSj0L3Gg4P4d3UrZSQfeho6b7b7DpEPR46241v3Tqb2SvwLfyAhJy59Cc4b X-Received: by 2002:a17:902:e546:b0:1dc:8b82:7f56 with SMTP id n6-20020a170902e54600b001dc8b827f56mr246005plf.20.1709143427726; Wed, 28 Feb 2024 10:03:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709143427; cv=pass; d=google.com; s=arc-20160816; b=B5M40lhMjtSkkr9lId7hhYf6aJZBcUUICGkgqftdPIZqhCW7utOEzYHUlyMaYjp0DC yGEO5jJ2aSaHrCz3nSm/DudYhGjGnW4MOKVu5x0OO935ndNm+j7cUTvHmdYfAoWdgu5a gWFZu2VF09rexaLA838cKePMgWG6OOjYUBKB0VNmx6Evq9JwMKVzy6QVc4InFcsuIO7P /R77dcilBihd2EJDZlw+6edupIJn66k/2Ojz+1TSNl0X9AXlpoRWIMnEhROiPP1VwjEu cGCSmSqd4U7Z/XIp192ei/xxYTT/rXYiYSSRMbbvqcRWphivQ3LM51FT0EibCHxhd6Pg 6/8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=ZQYfGRlMuAzV9NGrkcAH7hkAKHgrR0yYSvegD/d+xL8=; fh=99A43Mczr46B4mXCeciOIN83hDofSOLKaQv33fb8biQ=; b=o0YW0FZY/hqhhBUyJ9LRP1E1YSgMHGjFh4inW8DESAwuhFQOYRLAroUKdzFeicLVkc vwqhKtK4MgXv+NaW5Uq56Go1d46xKuJr9PxJ1i5nQ5i9igR2dV9NIGEJoUMCo7dSLueU hHYivsUBx/gq1MPMUJOQxgiNTftoI7Qwd6KJu+BhIPiTiZ7Iwyk5ThDr9AY18AKT/erX l4XBxZHZCZvmjfJbIvt29Lb8mmRi1Tja8/GKIKYH+oKcCeJMOClIErQiMnzfBAUQP7/B 4HnomHnWv04p6/hWr+FYDk6YuWr7A3OvuphLD3ELKmMjt72f/54XfphPDw4pYTOO5A6D XT7A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ymi35g3E; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-85458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85458-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id z8-20020a170902ccc800b001dcd2fb75dasi438767ple.361.2024.02.28.10.03.47 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 10:03:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ymi35g3E; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-85458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85458-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2809EB214EA for <ouuuleilei@gmail.com>; Wed, 28 Feb 2024 17:44:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 637B715E5A9; Wed, 28 Feb 2024 17:44:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Ymi35g3E" Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDACB3FBB0 for <linux-kernel@vger.kernel.org>; Wed, 28 Feb 2024 17:44:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709142251; cv=none; b=LVc+DGnubN2PR3z5a4ZIWSJHBIMqrTNi/shBTzNTPhdlX1Lk4xssWfA+ySqvL53Nf1Pfdy5Fcdd7khSve0FtUUxMbiDOc3vLiYP4AifDy+ZUp+q9BAgSOoh/DNKZGfcea0U3vdiP0w8zXnYg3+4k3BGiCFsdoJaZ7D36AsIeC0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709142251; c=relaxed/simple; bh=W6V/WUDrcU6ltqu9bzNaahvrM7LME69p9CtE6KRKCd0=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=qGeuyO8GtFDi10GYyXbPZO7CI81ghAaXx0cFtMvx/SwjsegIfrc4fpoRzd43RT9+r+o6CHioMp/aA+8M6ntVeZyQ/6P64YuAIH7eJTdwsCgk0wCCVuiDc4j9uVVEtQqT1WkTHofmU5FODoto2aXFpornsLjsOptOHMO/lKcS8fM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Ymi35g3E; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-412b4a12bbaso59905e9.1 for <linux-kernel@vger.kernel.org>; Wed, 28 Feb 2024 09:44:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709142247; x=1709747047; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=ZQYfGRlMuAzV9NGrkcAH7hkAKHgrR0yYSvegD/d+xL8=; b=Ymi35g3EEvkMiXXIouWabZ77SZcpf2PnI9YixiRbeWetDQW5jVnR0/tzDLx6B33lb7 mEwhM0o+GsJ15JdH2I6QtSJLUYiyKJgdytf/qU+QbIwuGU7J+3R23l2p8jLII2PFUyCt PceCeRRomVtvwV+l8Koe0VfAakSwMeFBzADIFlk6wqyuuT4YvR+uD8GQ7aDsv8xi/ICF 06tkgwhsxkzWc/Q1qG/b0shlaVDg0dwtmk1SxZu68jzKN+zpn/QxyK6D8f9Tw7DRuhVY KhU/LS6YLpruRlZqJiJIGkW+IKx8HruMK4gJC4BIGSShmpPYew7tLI3BQ/QpP7ICcQK1 b1yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709142247; x=1709747047; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZQYfGRlMuAzV9NGrkcAH7hkAKHgrR0yYSvegD/d+xL8=; b=B9GAfJUKDhxZO8cJ8D/5qyCWpaVrB4icbaUfplQYAxnwjMtXMyBfE6TyJX9BdByBNa 6NEauhylqsh7892l7WUahG3PW6oYQ1AQuUTATnnZ5JfdzF9PiFcHJtyNVW/8phI0VADf uYq5JDBLu6cq9XGybSTVaDWXvWbyz+K0ylK28x7n0dJLoypTWiB7lsUpUdqG4ZJN5r77 8EEySx/01EV96U0drwDNJjqsFFSGAuq7XAdV8uePScH69IdNbwF9GjHbH2dlQmBNL1uN DisVug3X8vwSy+YTmIcoIVngz4fk37/mOCpF6pC+bXNmbcJPNA9bwRjB7CSIrw/5kAGK YaAA== X-Forwarded-Encrypted: i=1; AJvYcCUyWUpGxpl/NQegIoR05ji3jwAbGPDIDjIB6W79JbQLE2Yj4l7eV9sltmn4aZlQCMZ+x+M4LdeeH6TK0BRrHjM5duiPIia/hq84791v X-Gm-Message-State: AOJu0YxO+NSgSRRsyjkrhUIL3BpuuRFD4W4OtHCorGtpi1oOzAdyjVYP AjEL9I8neK0OupR6BmE5XQ1pWSLFSgG4Cz6/KRO79phByEsqwIA8Is+qphRjotY= X-Received: by 2002:a05:600c:468f:b0:412:64a5:a21 with SMTP id p15-20020a05600c468f00b0041264a50a21mr127317wmo.40.1709142247357; Wed, 28 Feb 2024 09:44:07 -0800 (PST) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id j10-20020a5d564a000000b0033e0523b829sm1008975wrw.13.2024.02.28.09.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 09:44:07 -0800 (PST) Date: Wed, 28 Feb 2024 20:44:03 +0300 From: Dan Carpenter <dan.carpenter@linaro.org> To: Cindy Lu <lulu@redhat.com> Cc: "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>, Xuan Zhuo <xuanzhuo@linux.alibaba.com>, Xie Yongji <xieyongji@bytedance.com>, Maxime Coquelin <maxime.coquelin@redhat.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Christian Brauner <brauner@kernel.org>, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH v2] vduse: Fix off by one in vduse_dev_mmap() Message-ID: <e2361611-e8e3-4c6a-9f71-30e81a65f793@moroto.mountain> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792067766086739445 X-GMAIL-MSGID: 1792166779189843377 |
Series |
[v2] vduse: Fix off by one in vduse_dev_mmap()
|
|
Commit Message
Dan Carpenter
Feb. 28, 2024, 5:44 p.m. UTC
The dev->vqs[] array has "dev->vq_num" elements. It's allocated in
vduse_dev_init_vqs(). Thus, this > comparison needs to be >= to avoid
reading one element beyond the end of the array.
Add an array_index_nospec() as well to prevent speculation issues.
Fixes: 316ecd1346b0 ("vduse: Add file operation for mmap")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
v2: add array_index_nospec().
drivers/vdpa/vdpa_user/vduse_dev.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Wed, 28 Feb 2024 at 12:44, Dan Carpenter <dan.carpenter@linaro.org> wrote: > > The dev->vqs[] array has "dev->vq_num" elements. It's allocated in > vduse_dev_init_vqs(). Thus, this > comparison needs to be >= to avoid > reading one element beyond the end of the array. > > Add an array_index_nospec() as well to prevent speculation issues. > > Fixes: 316ecd1346b0 ("vduse: Add file operation for mmap") > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > --- > v2: add array_index_nospec(). Did you forget to update the patch, I don't see array_index_nospec()? > > drivers/vdpa/vdpa_user/vduse_dev.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c > index b7a1fb88c506..eb914084c650 100644 > --- a/drivers/vdpa/vdpa_user/vduse_dev.c > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c > @@ -1532,9 +1532,10 @@ static int vduse_dev_mmap(struct file *file, struct vm_area_struct *vma) > if ((vma->vm_flags & VM_SHARED) == 0) > return -EINVAL; > > - if (index > dev->vq_num) > + if (index >= dev->vq_num) > return -EINVAL; > > vq = dev->vqs[index]; > vaddr = vq->vdpa_reconnect_vaddr; > if (vaddr == 0) > -- > 2.43.0 > >
On Wed, Feb 28, 2024 at 12:53:28PM -0500, Stefan Hajnoczi wrote: > On Wed, 28 Feb 2024 at 12:44, Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > > The dev->vqs[] array has "dev->vq_num" elements. It's allocated in > > vduse_dev_init_vqs(). Thus, this > comparison needs to be >= to avoid > > reading one element beyond the end of the array. > > > > Add an array_index_nospec() as well to prevent speculation issues. > > > > Fixes: 316ecd1346b0 ("vduse: Add file operation for mmap") > > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > > --- > > v2: add array_index_nospec(). > > Did you forget to update the patch, I don't see array_index_nospec()? > > > > > drivers/vdpa/vdpa_user/vduse_dev.c | 3 ++- ^^^^^ I updated the patch but the thing about vim is that every time you press a button it does something unexpected. Vim ate my homework. regards, dan carpenter
diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index b7a1fb88c506..eb914084c650 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1532,9 +1532,10 @@ static int vduse_dev_mmap(struct file *file, struct vm_area_struct *vma) if ((vma->vm_flags & VM_SHARED) == 0) return -EINVAL; - if (index > dev->vq_num) + if (index >= dev->vq_num) return -EINVAL; vq = dev->vqs[index]; vaddr = vq->vdpa_reconnect_vaddr; if (vaddr == 0) -- 2.43.0