Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3406312rwa; Tue, 23 Aug 2022 04:22:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR659Ghy56Big8fdiwhuW+N2FkbsH92koiSVBp70HDZA578cvpEOeIZ1fos9zzn0/cwVPHPO X-Received: by 2002:a62:ea14:0:b0:535:c678:8106 with SMTP id t20-20020a62ea14000000b00535c6788106mr24980407pfh.9.1661253721163; Tue, 23 Aug 2022 04:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253721; cv=none; d=google.com; s=arc-20160816; b=pwtyMsZxZVP/rhoZuCqKIMj49QCIzVHFW/1GESSj+fyd45FU9WUKpHSFemZRYdPlls wKb18wgDWdTbih1kXuRgyo6QdjZz4XEGG3SavDBZC9nglgl/jVnWm/4Hz5ibclS8/bbx 9uYOvm71UcFLYnjt8/GTd/G9E0M6gsYtSRvlcV7vyt5j6Dc06L9NuS7K8o7Rq8gHdbn8 o1n2/27NmQXl/y8APlRU0KiEsrQA0jkJG8ZR7Q/gywlZnTW2sCyheDumeKrDOC95X1Zd rg5PES4o4Yv6b4d+iFpxohTDwjtLuNpPLCw/ZkEH11rJy004ht5zuWaJMtLmtzbH0Mxa IWGg== 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=yyzmakBMUP+Yg2p52CAv1s6XGHVdruDZPaUPaeb0HOU=; b=RkuxxU5ypR3CRtACuYfwh15v7XTLsKK9+dzvSzeKh4exLSYmJuNm/FCrqV4sXOslqt 698vVe/4d90bWNR/zPqSgiTNUg1EqCpbAi84eWOKfsmT7LPvWiEsPkcBsNgQQyhFoagF qinZZLDGaJkE7ldFt3FMMuwchTg3DlmCBXZp4/uWnGhB5RU98DNGy/1m0DT3rlQHPqs7 i0he/ueaqEI04jRp6/UOUGjFQPopjglwOHbWbgYx06UZB4rDqKJvP3cTJ2iQQ+aumACQ aYaCyeYI2qWweBSfx1Flwe1YD+oUbtVkXzA8cssnF0O7erSqxJo60jDLhXqYKIxvBtY0 nGUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DrbMX9IY; 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 o16-20020a170902d4d000b00170a752cae8si13182074plg.115.2022.08.23.04.21.50; Tue, 23 Aug 2022 04:22:01 -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=DrbMX9IY; 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 S1355148AbiHWKXA (ORCPT + 99 others); Tue, 23 Aug 2022 06:23:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353316AbiHWKLO (ORCPT ); Tue, 23 Aug 2022 06:11:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 793A610A; Tue, 23 Aug 2022 01:56:31 -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 16602614E7; Tue, 23 Aug 2022 08:56:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D408C433D6; Tue, 23 Aug 2022 08:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244990; bh=aYnBnfGUaEEa3RlKev2F+dQui8GePYWC7nN4kwgsqF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DrbMX9IYej7wZHvaSrZVjF1Vq/Y4N2jxdLrELV1YVD2xQ6OAdiReHpXNSpYf7cxa0 iPlvEEOAdd9x/Ztyxyg3NYdMi/2VKNUPLoK1rVgdus+1jYey/McE4q2OTVBLLXmzZr K3J40xmBc9v3hcTCz3TJ1DnQcOU/edpOloE1XpMo= 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 4.14 226/229] smb3: check xattr value length earlier Date: Tue, 23 Aug 2022 10:26:27 +0200 Message-Id: <20220823080101.714839062@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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 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