Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2893958rwb; Mon, 15 Aug 2022 13:29:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR5HRfE5R66apMStf3TbTH3d063uUMy8QNwkg86LiKcp5UlgPgLHKJjQpJ6K7a5+Ute4yvPG X-Received: by 2002:a17:907:16ab:b0:731:55c0:e7a1 with SMTP id hc43-20020a17090716ab00b0073155c0e7a1mr11495881ejc.154.1660595361352; Mon, 15 Aug 2022 13:29:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660595361; cv=none; d=google.com; s=arc-20160816; b=Sgewe64a9rgxZ/4J0cOxZbddAj7LJoGFoprqAX6M4cvv0r69BHdb6P6WyTw309eN0H Fxf1tytjV0+BRhD/kirBWyrzEBle0WQy2XvISmd2j0r3PKNDzkLZI2RzLXomJwEZ39UC PbWuvspS4lm3BcEL0b0ffflslktDtOuAC/xj+MYgjARBTck+EcoSBp6qzMQb0/N661FD 6X5ZKdHntXSSbRBb6PGqM4m8Nd5KwPt5slCQYzJsEB19a9PVSLC9EaCORE0In/QJivpR GK0UwmLssdRhfCAOHupmG4sNucQKHEgFR69yG9Uy9L0kvA9pTsltLFw6ZpKTLSiPCjH7 gTSA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RFVhRNOu9rtoQlKsJ4C4I5iY3Iz5y2ciJVah+/yx/hg=; b=lWdedvMp1jFTyr1+67p2LoOqSpxrFZDoSdDARkVbuK+/pxPDDTIRt17jVionLNj6ol abcbPks6QE5wqB1YpZRnjUVkgVKfSTwEjHvAJwF4XjjUuGV47ZxDTcbncFMk8wlfoWTH +1qFUVVD+/j62Ww6rfgrcF4asEU2Kte6byOByWgG8c5PJP0NYhXRhHOXP+BQbUGYaNxr 8W/GUP94PtQOOgMwdk3J/09yp+HhLLhl/NbEd5sTzrpr8pxXkXENUQx9IB9V1H8FBqNc eOs3fcVENm0GPqWE+QqDy85e0qkNX924fUdvdd/IbF3unzuqQoTwOUbnOdoSR4GhHSwM oyow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NqZaVyJz; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ft16-20020a170907801000b0072ed0d06c0csi7003481ejc.411.2022.08.15.13.28.49; Mon, 15 Aug 2022 13:29:21 -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=@linuxfoundation.org header.s=korg header.b=NqZaVyJz; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347613AbiHOU0O (ORCPT + 99 others); Mon, 15 Aug 2022 16:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343928AbiHOUTY (ORCPT ); Mon, 15 Aug 2022 16:19:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD85780516; Mon, 15 Aug 2022 12:00:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F022EB81106; Mon, 15 Aug 2022 19:00:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EE71C433D6; Mon, 15 Aug 2022 19:00:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590037; bh=bqOWLUEtmJFZwXCw3UqJncyrYlm7mOE2OSE/xVhMHtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NqZaVyJzBqvjBFJeKFM9jOemJHD9cqZkrfvG1G+V0SonLdB/SRBTgApPrtcacAiSA w29w/h9eIVZIhdCYaOS6RIIxuZjdMiScUb+77qoghAW3TvodKnpmFbmdQ+szWob+a3 O5Gm0yzZNj+fE32rq7jSI+Ref9VfE4jICt2I1utQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hyunchul Lee , Namjae Jeon , Steve French , zdi-disclosures@trendmicro.com Subject: [PATCH 5.18 0100/1095] ksmbd: prevent out of bound read for SMB2_TREE_CONNNECT Date: Mon, 15 Aug 2022 19:51:39 +0200 Message-Id: <20220815180433.689786833@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 From: Hyunchul Lee commit 824d4f64c20093275f72fc8101394d75ff6a249e upstream. if Status is not 0 and PathLength is long, smb_strndup_from_utf16 could make out of bound read in smb2_tree_connnect. This bug can lead an oops looking something like: [ 1553.882047] BUG: KASAN: slab-out-of-bounds in smb_strndup_from_utf16+0x469/0x4c0 [ksmbd] [ 1553.882064] Read of size 2 at addr ffff88802c4eda04 by task kworker/0:2/42805 ... [ 1553.882095] Call Trace: [ 1553.882098] [ 1553.882101] dump_stack_lvl+0x49/0x5f [ 1553.882107] print_report.cold+0x5e/0x5cf [ 1553.882112] ? smb_strndup_from_utf16+0x469/0x4c0 [ksmbd] [ 1553.882122] kasan_report+0xaa/0x120 [ 1553.882128] ? smb_strndup_from_utf16+0x469/0x4c0 [ksmbd] [ 1553.882139] __asan_report_load_n_noabort+0xf/0x20 [ 1553.882143] smb_strndup_from_utf16+0x469/0x4c0 [ksmbd] [ 1553.882155] ? smb_strtoUTF16+0x3b0/0x3b0 [ksmbd] [ 1553.882166] ? __kmalloc_node+0x185/0x430 [ 1553.882171] smb2_tree_connect+0x140/0xab0 [ksmbd] [ 1553.882185] handle_ksmbd_work+0x30e/0x1020 [ksmbd] [ 1553.882197] process_one_work+0x778/0x11c0 [ 1553.882201] ? _raw_spin_lock_irq+0x8e/0xe0 [ 1553.882206] worker_thread+0x544/0x1180 [ 1553.882209] ? __cpuidle_text_end+0x4/0x4 [ 1553.882214] kthread+0x282/0x320 [ 1553.882218] ? process_one_work+0x11c0/0x11c0 [ 1553.882221] ? kthread_complete_and_exit+0x30/0x30 [ 1553.882225] ret_from_fork+0x1f/0x30 [ 1553.882231] There is no need to check error request validation in server. This check allow invalid requests not to validate message. Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3") Cc: stable@vger.kernel.org Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-17818 Signed-off-by: Hyunchul Lee Acked-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/ksmbd/smb2misc.c | 5 ----- 1 file changed, 5 deletions(-) --- a/fs/ksmbd/smb2misc.c +++ b/fs/ksmbd/smb2misc.c @@ -90,11 +90,6 @@ static int smb2_get_data_area_len(unsign *off = 0; *len = 0; - /* error reqeusts do not have data area */ - if (hdr->Status && hdr->Status != STATUS_MORE_PROCESSING_REQUIRED && - (((struct smb2_err_rsp *)hdr)->StructureSize) == SMB2_ERROR_STRUCTURE_SIZE2_LE) - return ret; - /* * Following commands have data areas so we have to get the location * of the data buffer offset and data buffer length for the particular