Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3402945rwa; Tue, 23 Aug 2022 04:18:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR62TroahtHkHBXDdKFE0jt+ran+QpThzNtC/X8AcLIejeEBjmTSs4M9nLEXJU6payTnwJOL X-Received: by 2002:a63:4e25:0:b0:41c:62a2:ecc3 with SMTP id c37-20020a634e25000000b0041c62a2ecc3mr20571444pgb.596.1661253527913; Tue, 23 Aug 2022 04:18:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253527; cv=none; d=google.com; s=arc-20160816; b=aen/vRDwqg+5t4A0mnOLZCsPjeseK7BhpmheYig+CB6P1JMEduR1AAxMMMqLlTv4I5 zqhyZI+L1aRuOJm2AtB7iwoI98o9ueY1PBi/duGTBgsEtRV1n+f8xwN+m47cGEzT8mms dE6LM+i8d3GBwPLrrK/tjM9vfuo0Ep2kA49bmujCErR00ZmGtaBxEn1JyLz/4gb+XkWg P3XmtRhOvPX5K1dN2uM60ylRZAEwqF8wWDhS1Ujg9P+FFnqx/N9dCIuJ7EshcC7dr4Iu nRR0zqQx48jw1Vg5uzZrxpmG/KkHXVC4C7PWs5X1Sx0X7bNPm8X6lYw0+3ISoqe/qT0A cHNA== 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=sVTNw0Jr3zW7zHTS4c26Rj345fa1LMIHYjSPVdmO5rc=; b=Qo9qkiWnABeFV08Tg06F4hXTBDTUored8UjDYraicgdl5nVIdAN0V+b1uNiXdiFrVr oV62vzlcsA0rmwVJbKmnugqSYMX62EjGv9TAa3TEUHmVcnPegFFrB2/uP+jL+vPZMBOu 0rd+eR4SPQNmOFHLGp6kPrg048TCVF+zewSj4VVzQv1iAiTP+m7Gs4yC714log22bobD M8SANOKd/f7OOf3kA52xoMmg8JYTAekVt/Rd0RxHpXJq2lJ8hKFBSn/Mt83MiFb05TTG pv4Q+MLDhAFxSuWLk2WChsO0777NuRLF3tGJBYXCBosrf7v/VZzzo2lYTTq/c4sZpBKO vxmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=szfLOoXs; 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 36-20020a631864000000b0041df966444esi15335419pgy.59.2022.08.23.04.18.36; Tue, 23 Aug 2022 04:18:47 -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=szfLOoXs; 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 S1354210AbiHWK2s (ORCPT + 99 others); Tue, 23 Aug 2022 06:28:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353086AbiHWKNA (ORCPT ); Tue, 23 Aug 2022 06:13:00 -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 32D6D4F1A8; Tue, 23 Aug 2022 01:59:01 -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 D7017B81C28; Tue, 23 Aug 2022 08:58:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46F62C433C1; Tue, 23 Aug 2022 08:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245138; bh=AR7Ip3kl2XlY0ZQseaklUDElSuk4HH4NTMx0bp4+/TA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=szfLOoXs8wSKRVpv5MDaOf29mUfGiAht9Z/WMjaBDy6m3zlexONtrYdmmDmEqWJpV mRfcckYsNvTNsi31xPx4MwAYSEZoc8r6nGrL0W0yiCJxP0eTgMXGXo8i+2BO8tLjwn SkKMoTSbrQT53dyXw00gzrTupIwWbDVnuwDKjb+E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ronnie Sahlberg , Steve French , Sasha Levin Subject: [PATCH 5.15 229/244] smb3: check xattr value length earlier Date: Tue, 23 Aug 2022 10:26:28 +0200 Message-Id: <20220823080107.193865973@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@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_FILL_THIS_FORM_SHORT,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: Steve French [ Upstream commit 5fa2cffba0b82336a2244d941322eb1627ff787b ] Coverity complains about assigning a pointer based on value length before checking that value length goes beyond the end of the SMB. Although this is even more unlikely as value length is a single byte, and the pointer is not dereferenced until laterm, it is clearer to check the lengths first. Addresses-Coverity: 1467704 ("Speculative execution data leak") Reviewed-by: Ronnie Sahlberg Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/cifs/smb2ops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 735aafee63be..07895e9d537c 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1105,9 +1105,7 @@ move_smb2_ea_to_cifs(char *dst, size_t dst_size, size_t name_len, value_len, user_name_len; while (src_size > 0) { - name = &src->ea_data[0]; name_len = (size_t)src->ea_name_length; - value = &src->ea_data[src->ea_name_length + 1]; value_len = (size_t)le16_to_cpu(src->ea_value_length); if (name_len == 0) @@ -1119,6 +1117,9 @@ move_smb2_ea_to_cifs(char *dst, size_t dst_size, goto out; } + name = &src->ea_data[0]; + value = &src->ea_data[src->ea_name_length + 1]; + if (ea_name) { if (ea_name_len == name_len && memcmp(ea_name, name, name_len) == 0) { -- 2.35.1