Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2843490rwe; Mon, 29 Aug 2022 00:50:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR6xtO8rBEke0hSEubSsqVDTaSayNET3Jssiva2/2BhXFtZmIZ6ROsB+joUQRyJNDVHCJHd0 X-Received: by 2002:a17:907:2bc4:b0:741:5242:e0c6 with SMTP id gv4-20020a1709072bc400b007415242e0c6mr5636627ejc.229.1661759441086; Mon, 29 Aug 2022 00:50:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661759441; cv=none; d=google.com; s=arc-20160816; b=Oj/46I8Qnx6eRyz9l292w06MO/K/94U5Dmw5vYAfVWDo2Yaud1AlL4Di0WVTvtJ4JH 7E6ItyNLljhhJWcokcROdMcCjixDuzYdO7x7AsCpEXdEtOaQULGQarudRDzN+MbbhDwX fF8IApqZtYAKCrslF/cANt9Kh3N7Pm73XMjkaMIyD6xT3UeRtIzM3AHtBfXS+2Sjw89j QJOme8tYzhwwYAYVLhU5/5MpKfFcprtwzwwAaSDO6FhhCJqD+KeCnhKJEHRTuGHFbEHg p2yccm/FdNcRnAtH0oh5M31tIsDZQ0GGZvhnxnmWnIpYnI9QuiXubOfuwdutudFXD37v hTjQ== 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=ivp8SkSbzWYeukb9RmMR/+ypBwoHgCA1ggb1pX9wCGY=; b=r6MIC4eeqvd+hyzjQ0hsibfsl1x74IKBrLq7aBb5YpMJOudNLA3idON5QKtavQZ6Kh jOXyQX6ecOCRUNwDuCS5G2FzRMOnwdLJwXDuZo7VrYAWkcByavTAf8HyaiXZDY1xeatq 2qYxj4M4Tk/xttFIa5WY5hGmzjDXNYNZ4N/xJ1+1W1FP72PPMAXvC0fuho6uX9wYVQ5d YPRlF0FvUvDJxWWZDSHNsZog+x8MnPnuepVDvFdnl5Nm3z0a8NtwuWfWaLyfsZCsdYGH okDJ+7A24FhhOsTV7mgVONJ9DlUcOzK9UippCUs7GAzujTpnnkhNyTWwkd6G65e0BpHU NzCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DTFfXWyc; 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 dt19-20020a170907729300b0073d7353d1ffsi6120898ejc.860.2022.08.29.00.50.16; Mon, 29 Aug 2022 00:50:41 -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=DTFfXWyc; 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 S229610AbiH2Hew (ORCPT + 99 others); Mon, 29 Aug 2022 03:34:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbiH2Heu (ORCPT ); Mon, 29 Aug 2022 03:34:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B290271E for ; Mon, 29 Aug 2022 00:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661758487; 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=ivp8SkSbzWYeukb9RmMR/+ypBwoHgCA1ggb1pX9wCGY=; b=DTFfXWycfJpWbAOyn9oON/hcj88O94olHPcfZdto3R4S9OW+JI1V3uM9gUytn9wPOKsME8 8ky9bumyxm8/5SWUfAGIhzKOzTkOoSI8N/Y7ayw8AKBI0AY9rJV7F6Eg7IMrBXfkabFiOh 4b4bxq6KokclnOmQpVX6HheONFaI5bE= 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-433-XdSkkRb2Pn6saeyjF857mA-1; Mon, 29 Aug 2022 03:34:43 -0400 X-MC-Unique: XdSkkRb2Pn6saeyjF857mA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1E77B185A7B2; Mon, 29 Aug 2022 07:34:43 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAA65492C3B; Mon, 29 Aug 2022 07:34:40 +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: Maxime Coquelin , stable@vger.kernel.org Subject: [PATCH v2] vduse: prevent uninitialized memory accesses Date: Mon, 29 Aug 2022 09:34:24 +0200 Message-Id: <20220829073424.5677-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, 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: xieyongji@bytedance.com Cc: stable@vger.kernel.org # v5.15+ Fixes: c8a6153b6c59 ("vduse: Introduce VDUSE - vDPA Device in Userspace") 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