From patchwork Fri Jul 16 10:22:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 12381895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45F80C12002 for ; Fri, 16 Jul 2021 10:23:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F578613F7 for ; Fri, 16 Jul 2021 10:23:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238968AbhGPK0f (ORCPT ); Fri, 16 Jul 2021 06:26:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238398AbhGPK0b (ORCPT ); Fri, 16 Jul 2021 06:26:31 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAD65C061765 for ; Fri, 16 Jul 2021 03:23:36 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id b12so8553752pfv.6 for ; Fri, 16 Jul 2021 03:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mJYWdsw34aaRbO5ru3xen2MP+EZCEf1FnSIinPAOBxs=; b=lfW3C2RlMykUor71r2BAqRYYlG/PW0KIuSkBiSttDLmUoxPDOjn+FANYMaPFQDPbgF 0ZGWE6wcWYKK0bXHb9Y9xQepzfzmilg/oDUoxtf60gjKQ2N318O8yABWEOP02o6Nd/Wa w6Gm6X8EYCVu27mecSuqpL0zooyyAgcek6s646cFx1q/xsQa/U5Txad6U5hXYOX2Q62L Cm9rS1Hh1nh03KWD1UaFQyrdp7uEUdH0/wuZqvMI4AR42bYV9bFSE2SyPfVEI+xmhw1j ESfq9gRb/fXf2qyyKZUvuGoZpEfJU+Jyls1nO52IIE88k3Pn8jSmB86NDTMuWC5WDW9r 1+/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mJYWdsw34aaRbO5ru3xen2MP+EZCEf1FnSIinPAOBxs=; b=kwctV7tNfe9FaQqlhqJoFaX0CmrTPU3z0dGne9IW0/kpFmrizt6Xy9vvDlvY3YX4VD usVCnBUhz3abA6S1gJB4vb3GXyFMCXv39p6vMqjJDK9orZEVly2MReZbT+jRJemVGhjt KHfGYlWsVePg8G2TPwwZsrjfWX4WTpMx73Ig9QT+NJqks0Wn/4V3tfUfSveGkERnDzVl fnsEU7eD4AcEep8GiPVyqdh6dT9FLpL8MxZEHfWEAdiXHTdIJXEliEX75ZgxcHqFSR7T Ajk1lgYV5QapFIihCWsupqieyTV4ZteR5YNMqJ7zZrYYyl/CWkrUcF/oBOCGRjS1t40V JTyg== X-Gm-Message-State: AOAM531FKlvJvYM8OH5cZiI4VXhz4TRYyqwQRcWjCJViEmCXsnc+9p9a 20pQm7bjKgpNhoBICAjRggDU X-Google-Smtp-Source: ABdhPJxONsQNT4fPjubNFPLig4RCYzRSiNrG4NZUr7bg0TGdIHNu5HB6tFcl+zKNW/s/fpUFw6yJaQ== X-Received: by 2002:aa7:854a:0:b029:332:330e:1387 with SMTP id y10-20020aa7854a0000b0290332330e1387mr9452917pfn.67.1626431016369; Fri, 16 Jul 2021 03:23:36 -0700 (PDT) Received: from localhost ([139.177.225.253]) by smtp.gmail.com with ESMTPSA id 1sm9961963pfv.138.2021.07.16.03.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 03:23:35 -0700 (PDT) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, dan.carpenter@oracle.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] vhost-vdpa: Fix integer overflow in vhost_vdpa_process_iotlb_update() Date: Fri, 16 Jul 2021 18:22:38 +0800 Message-Id: <20210716102239.96-1-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The "msg->iova + msg->size" addition can have an integer overflow if the iotlb message is from a malicious user space application. So let's fix it. Fixes: 1b48dc03e575 ("vhost: vdpa: report iova range") Reported-by: Dan Carpenter Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vhost/vdpa.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 210ab35a7ebf..8e3c8790d493 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -615,6 +615,7 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v, int ret = 0; if (msg->iova < v->range.first || + msg->iova - 1 > U64_MAX - msg->size || msg->iova + msg->size - 1 > v->range.last) return -EINVAL; From patchwork Fri Jul 16 10:22:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 12381897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81C04C07E95 for ; Fri, 16 Jul 2021 10:23:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70412613F9 for ; Fri, 16 Jul 2021 10:23:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239001AbhGPK0h (ORCPT ); Fri, 16 Jul 2021 06:26:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238938AbhGPK0f (ORCPT ); Fri, 16 Jul 2021 06:26:35 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98000C06175F for ; Fri, 16 Jul 2021 03:23:40 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id k20so9516228pgg.7 for ; Fri, 16 Jul 2021 03:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O+aoi4mzR9R0iZuLemuHjtXgfA9womLoAerCtxXTQaU=; b=EGvXh4cu9xHTBQMHWEdPcpq0Cehs0/omnlJ7DpLTRy4lJ44ulzrdc7Nk6Ng1rMSWCF on1ymYszZTIM8tY2LL6bBOOvdANp+flT1o+DR0mo/1esxdpEll1K9tjgfnVCidwoumyR UBy1cO9cYEGzMGNL15FYBzmsA9K1iIb/PGJmy38XQFZRA52RKVxwNm6u4DWKuR6uJSrd 2mHjCoJmKdM13gH+qPdJJz9xV6k4UyJhC6xMxFXwKFOmBOMEY49nrwL/daEURrsrbn4l UJXsTjUl0kZ67KBVXHNZatfysQn7hG+yrBf0qZT99bB49bgr6nW9Rr/jrpwW1uW4n0+V Holg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O+aoi4mzR9R0iZuLemuHjtXgfA9womLoAerCtxXTQaU=; b=e7DbYn+l7e8gowURE5ZOo9JjqeSIRL7i12kgfs5YCnpDpJ4TJs1jx3UNwKqoBZKZPJ l5FVY7yVFM92W9zRe4fHYzRtlR3DssbfduVIilahYEC+C4o9/8k9RvHquwynrtWoPaJi 4ElEhwr9JydTPfTbDHCSIMcvFWmKilYVBbOiLoKXplmC0u40MLe6/p/hTpIp/9ceQcSk qf5MFn7CI6IK1ua1RqCNIDwZ++ILsbhxiNOE4a8tM6gTqS4trMBeNXtWzCUBn5N695C1 nvnOg5Hjfd7jkIw78fexBqPvUYRl0Xe5rjFL4jMX1WGGeCIs5wnvSMwW/q8d6j8Dj+nV qTrw== X-Gm-Message-State: AOAM531v93eZah/Mk7zTVKKuNRWSoNbFi73y/QtzV9zLVL8lgk0j7TPe IT1/ex4y1+UNc9GeB16uVAei X-Google-Smtp-Source: ABdhPJxuw98GR5HK3YBPh9STuop2yfagNpyb+GFBdHn1W/rAoINiKBfEzL6gAM6RByS5JfWFM0Uw3g== X-Received: by 2002:a05:6a00:1a09:b029:32c:7b3a:837 with SMTP id g9-20020a056a001a09b029032c7b3a0837mr9616864pfv.36.1626431020225; Fri, 16 Jul 2021 03:23:40 -0700 (PDT) Received: from localhost ([139.177.225.253]) by smtp.gmail.com with ESMTPSA id k19sm8137435pji.32.2021.07.16.03.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 03:23:39 -0700 (PDT) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, dan.carpenter@oracle.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] vhost: Fix the calculation in vhost_overflow() Date: Fri, 16 Jul 2021 18:22:39 +0800 Message-Id: <20210716102239.96-2-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210716102239.96-1-xieyongji@bytedance.com> References: <20210716102239.96-1-xieyongji@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This fixes the incorrect calculation for integer overflow when the last address of iova range is 0xffffffff. Fixes: ec33d031a14b ("vhost: detect 32 bit integer wrap around“) Reported-by: Jason Wang Signed-off-by: Xie Yongji Acked-by: Jason Wang --- drivers/vhost/vhost.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index b9e853e6094d..a9fd1b311d2f 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -738,7 +738,8 @@ static bool log_access_ok(void __user *log_base, u64 addr, unsigned long sz) static bool vhost_overflow(u64 uaddr, u64 size) { /* Make sure 64 bit math will not overflow. */ - return uaddr > ULONG_MAX || size > ULONG_MAX || uaddr > ULONG_MAX - size; + return uaddr > ULONG_MAX || size > ULONG_MAX || + uaddr - 1 > ULONG_MAX - size; } /* Caller should have vq mutex and device mutex. */