Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7037685rwb; Mon, 5 Dec 2022 23:36:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf57/hHgG9iMNd5Eqv6M0W2QTwjtVDP4eqRsy726ug7TQbYRn7OFsEMij+3sBNsH/iw4uWUU X-Received: by 2002:a05:6a02:41:b0:478:6785:7df7 with SMTP id az1-20020a056a02004100b0047867857df7mr23488411pgb.168.1670312217587; Mon, 05 Dec 2022 23:36:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670312217; cv=none; d=google.com; s=arc-20160816; b=hFkaKPpe5/XuDnjgYmfn6SY8kzuTZQF+v2PfFKOrksbR+YXPj7GRjxRyJERajDNLbI po3DSiWhrJMZCNh+lugsaIxona8Nc0b65HdvaddXZPnLTb9G32yMjxqBSsizq8MDrtuk 1vxd1qliCss3nT0Rnn6j/zmXTZ0jOKHWt73yzTfZQV+CI8wXGgjIjiCp/0TVaRypeQqX isRdxbVUxg4IkIKhDYBq9r1SSlsl4myqPtW1fUiECibbAZw22sEFA9HC7iB5vh3WIO9o yIFxWJcZHeMPT7wbbhvePETaO1kODEY6+msJFH6yRHpUtXwdGvSokYsL6HWprrOM260M JbVA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eyicBLB+cXj5Epkqli1tqAK6DIdPvGnvCabjNRJb9ic=; b=EktDHWoWoGbyZvv+aabeBgaUHUGrTWZeWho8KMxRQ143djSXBM6T1gZSr1/h7nYKND kTliQokb2SAetqc77jr6TSX9+AAPo/HAIBwXLCuqKU7PgRO34tiWyYqipfN57I1Lx3K/ dC+iXxSLiu6eWSw04VJPZ+QPT6VNh6IH5Kcx2XLLm74CsafWrKPWi9jshva4FrxtcKNa tabMqHvH5AwLFTzQkATwDmIvJjrt2gXJQSW9Jb5Vw574SmOMBNBbOhqVezNMwZd0i1Zr k7e3vOkUFBkn4gTRzOJ1hyfgJLIw4rDEpiDBUE31UUaBIf7PayPIhg1F3KlgC1rIu3vt 4RHw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l13-20020a170902f68d00b00186a5b86ea3si18144350plg.50.2022.12.05.23.36.47; Mon, 05 Dec 2022 23:36:57 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230381AbiLFG6m (ORCPT + 79 others); Tue, 6 Dec 2022 01:58:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiLFG6k (ORCPT ); Tue, 6 Dec 2022 01:58:40 -0500 Received: from gw.red-soft.ru (red-soft.ru [188.246.186.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 48E8321E24; Mon, 5 Dec 2022 22:58:39 -0800 (PST) Received: from localhost.biz (unknown [10.81.81.211]) by gw.red-soft.ru (Postfix) with ESMTPA id 3407B3E1957; Tue, 6 Dec 2022 09:58:38 +0300 (MSK) From: Artem Chernyshev To: Vishnu Dasa , Stefano Garzarella Cc: Artem Chernyshev , VMware PV-Drivers Reviewers , Bryan Tan , Jakub Kicinski , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v4] net: vmw_vsock: vmci: Check memcpy_from_msg() Date: Tue, 6 Dec 2022 09:58:34 +0300 Message-Id: <20221206065834.1093081-1-artem.chernyshev@red-soft.ru> X-Mailer: git-send-email 2.30.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-KLMS-Rule-ID: 1 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Lua-Profiles: 173957 [Dec 06 2022] X-KLMS-AntiSpam-Version: 5.9.59.0 X-KLMS-AntiSpam-Envelope-From: artem.chernyshev@red-soft.ru X-KLMS-AntiSpam-Rate: 0 X-KLMS-AntiSpam-Status: not_detected X-KLMS-AntiSpam-Method: none X-KLMS-AntiSpam-Auth: dkim=none X-KLMS-AntiSpam-Info: LuaCore: 502 502 69dee8ef46717dd3cb3eeb129cb7cc8dab9e30f6, {Tracking_from_domain_doesnt_match_to}, localhost.biz:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;red-soft.ru:7.1.1;127.0.0.199:7.1.2 X-MS-Exchange-Organization-SCL: -1 X-KLMS-AntiSpam-Interceptor-Info: scan successful X-KLMS-AntiPhishing: Clean, bases: 2022/12/06 06:02:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2022/12/05 16:38:00 #20652685 X-KLMS-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 vmci_transport_dgram_enqueue() does not check the return value of memcpy_from_msg(). If memcpy_from_msg() fails, it is possible that uninitialized memory contents are sent unintentionally instead of user's message in the datagram to the destination. Return with an error if memcpy_from_msg() fails. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 0f7db23a07af ("vmci_transport: switch ->enqeue_dgram, ->enqueue_stream and ->dequeue_stream to msghdr") Signed-off-by: Artem Chernyshev Reviewed-by: Stefano Garzarella Reviewed-by: Vishnu Dasa --- V1->V2 Fix memory leaking and updates for description V2->V3 Return the value of memcpy_from_msg() V3->V4 Updates for description net/vmw_vsock/vmci_transport.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c index 842c94286d31..36eb16a40745 100644 --- a/net/vmw_vsock/vmci_transport.c +++ b/net/vmw_vsock/vmci_transport.c @@ -1711,7 +1711,11 @@ static int vmci_transport_dgram_enqueue( if (!dg) return -ENOMEM; - memcpy_from_msg(VMCI_DG_PAYLOAD(dg), msg, len); + err = memcpy_from_msg(VMCI_DG_PAYLOAD(dg), msg, len); + if (err) { + kfree(dg); + return err; + } dg->dst = vmci_make_handle(remote_addr->svm_cid, remote_addr->svm_port); -- 2.30.3