From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8385C28B2B for ; Sun, 14 Aug 2022 16:42:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243044AbiHNQme (ORCPT ); Sun, 14 Aug 2022 12:42:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243173AbiHNQj7 (ORCPT ); Sun, 14 Aug 2022 12:39:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55BC4DF9; Sun, 14 Aug 2022 09:30:22 -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 dfw.source.kernel.org (Postfix) with ESMTPS id E7A7560FC3; Sun, 14 Aug 2022 16:30:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88F28C433D7; Sun, 14 Aug 2022 16:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660494621; bh=aYnBnfGUaEEa3RlKev2F+dQui8GePYWC7nN4kwgsqF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qry4xrR6M4scGz76EXgyNxRDsIxC9YZFGvPZYeS+CQN1k9zPM6DQ/gxmv1teeNdb9 i5Dc12M23ZSyCG3NYhTaphN50O+I5oW1C49ewKThXKsUkQ/+YzQ/+QWHrDDq67Qmr/ UUDUFpag5EWGiNkl45a6DIGXqHpQfU4AIxWulaEgDvLzc99Ai71KOS/dJlt+UOeGnz /Hj5QqV48g2J/I/I7Grd2Jygbb66JmVUqvomma5clq59KxJKw0RjIeLOicBvRs+bL8 T1uRipWGPCF7WWWUn1XznWHi9h6iTHGvF+ia39lLwMdxWN/rgBSyZb8wl2xkSogiCA w5Mt5uh1n0oWA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Steve French , Ronnie Sahlberg , Sasha Levin , sfrench@samba.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org Subject: [PATCH AUTOSEL 4.14 6/9] smb3: check xattr value length earlier Date: Sun, 14 Aug 2022 12:29:56 -0400 Message-Id: <20220814162959.2399011-6-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220814162959.2399011-1-sashal@kernel.org> References: <20220814162959.2399011-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-cifs@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 3280a801b1d7..069eb2533e7f 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -463,9 +463,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) { @@ -478,6 +476,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