Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp690524rwe; Wed, 31 Aug 2022 09:18:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR6foK6XGrShXfIZIY7vnBCTSnIWkoCJoFWwJPQQLoy5UX5yi1h9vNWOz4jT5OGS/IXgJvrl X-Received: by 2002:a05:6402:440c:b0:43a:1124:e56a with SMTP id y12-20020a056402440c00b0043a1124e56amr25814546eda.134.1661962700722; Wed, 31 Aug 2022 09:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661962700; cv=none; d=google.com; s=arc-20160816; b=l3nbIITiKvkGtF6BM6VKKhkTb3cCwnQdizSTvNA1dzIJKERETIe9RRdErb4q+ebasC mulaUNvuszNnprIpnQUaIfSQXVKzkZyGLIebNdwAIvKgF7fB8mf4VW6A6CA0JJRRaGUo XKeGjgywtVA05bBuC7mn3a3rJ1LJzjOtEs/7Qo+7I7tFPslZxMn/WXZQDCrGrQHsMm7H rkFStINhReDa2KuKX+Ms+4dC/qwl3lt4MOBlGq65308D4JChsSneFAzLwTsx+AYyGQtB dXD4qIV52Ruq/a7ytVC9+4zUTT4Wg7dVGyyjK2pESq7d5Opv8/YfTgNPVVx8DWUg9PsE CxEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=q9qyQHrk2nVMvzPYEUreuyJ0t4W+wThvROhfwSArm9k=; b=wA6RzC23wcnH0aN0ZnpP0GRHWqTGTz/DfvKWMpqNMjRod/KNXM2tnZNgdxleBPh4gn JEGxbTJxdkIbTvb8annBZd00idRm2bcHvFUDp54Bb33uGduQ18Kc91jdlISJ7D+YCHIP ekJ5/Fg1mA/lQOsmDko+y+7JA0awitH35v9Ao7ikKXdqUlK+lgTUTANUthBWIzVDFwe7 yX7wio7OoFot9b6l5wNK3PdGfmG8YpAEG42NvhcnO5pKPQU8dnCobreHXIS1Vv6OXoVi +kKuJNk8G7nejUGYYz+4mwthzO+oahxMnb8nB/DizfL2cjDhAyhY4VD0ZIDq6+5xPYa8 Pkig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZZOC43E1; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020a056402271000b0044722838384si13891528edd.383.2022.08.31.09.17.55; Wed, 31 Aug 2022 09:18:20 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=ZZOC43E1; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230425AbiHaPt4 (ORCPT + 99 others); Wed, 31 Aug 2022 11:49:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231947AbiHaPtu (ORCPT ); Wed, 31 Aug 2022 11:49:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EED9E0C0 for ; Wed, 31 Aug 2022 08:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661960980; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=q9qyQHrk2nVMvzPYEUreuyJ0t4W+wThvROhfwSArm9k=; b=ZZOC43E1oeHWy3lEKZAL9xX4gTfY9CRj2lFPvJWOnQw9N9/c8cLOmt60hOfWYC5YLl+xBU RiXSq6qv87kr1Rjav/SVxDEJ1RAu/Oa2ZfY3I+Ak7+FnG9JvRRRXAdAsR+07sJg4xw4wxe h3bIuCcs7f34nX68TqghnAqxl+u6n00= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-596-k-QuRm5yOhqepR0DrqmzXg-1; Wed, 31 Aug 2022 11:49:36 -0400 X-MC-Unique: k-QuRm5yOhqepR0DrqmzXg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DFC20185A7A4; Wed, 31 Aug 2022 15:49:35 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 670822026D4C; Wed, 31 Aug 2022 15:49:33 +0000 (UTC) From: Maxime Coquelin To: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, elic@nvidia.com, guanjun@linux.alibaba.com, parav@nvidia.com, gautam.dawar@xilinx.com, dan.carpenter@oracle.com, xieyongji@bytedance.com, jasowang@redhat.com, mst@redhat.com Cc: gregkh@linuxfoundation.org, Maxime Coquelin , stable@vger.kernel.org Subject: [PATCH v3] vduse: prevent uninitialized memory accesses Date: Wed, 31 Aug 2022 17:49:23 +0200 Message-Id: <20220831154923.97809-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 If the VDUSE application provides a smaller config space than the driver expects, the driver may use uninitialized memory from the stack. This patch prevents it by initializing the buffer passed by the driver to store the config value. This fix addresses CVE-2022-2308. Cc: stable@vger.kernel.org # v5.15+ Fixes: c8a6153b6c59 ("vduse: Introduce VDUSE - vDPA Device in Userspace") Reviewed-by: Xie Yongji Acked-by: Jason Wang Signed-off-by: Maxime Coquelin --- drivers/vdpa/vdpa_user/vduse_dev.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 41c0b29739f1..35dceee3ed56 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -673,10 +673,15 @@ static void vduse_vdpa_get_config(struct vdpa_device *vdpa, unsigned int offset, { struct vduse_dev *dev = vdpa_to_vduse(vdpa); - if (offset > dev->config_size || - len > dev->config_size - offset) + /* Initialize the buffer in case of partial copy. */ + memset(buf, 0, len); + + if (offset > dev->config_size) return; + if (len > dev->config_size - offset) + len = dev->config_size - offset; + memcpy(buf, dev->config + offset, len); } -- 2.37.2