Received: by 10.192.165.148 with SMTP id m20csp2535120imm; Sun, 22 Apr 2018 09:03:25 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+xISFv87wB4/5nbdkwiGUFFEDnIUClnjcyP9T0jjJx/xy7wIQljue3iGxMpycmx6RpLXTp X-Received: by 10.98.105.2 with SMTP id e2mr17015534pfc.1.1524413005792; Sun, 22 Apr 2018 09:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524413005; cv=none; d=google.com; s=arc-20160816; b=v5A/k6aM0Vl7zsVhne0X00cT7JVILfOkxtX354wDKXmAd/t/9VWU0yS4Wa8sKyLnT0 lyxnlLBnnd+08Awn6RDaoxHC+Rcx2SLjVB91idqPX0eimx2JMlrRTluyuzp6u/UsjYj+ 1kMwBgkC9hhljPtjbqkywUeBTUszzUszz4q4uozi+/RtP8cWiaMGh9iiF1HSi9jtABbJ Vp8NWcyk5B+SG5j/ut/MAyOr104hOFdT80s947nUrSvkCGc2UmGKBGNzq3tVDP0x0Kl+ O8kYaSKOmP9NLBPLlezOmsg0sRhL3tRVHPB0yOxxJo+RgviCUJEoyg8ezcn/mPMEP8kx Ehgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Xvf7f5nwZmgHnFDau3q5i3qV7jcIvLnR8sQFJhcEDok=; b=qWd3J2Cpfooe7s/oe7hrWfMuQ+pQyGPYRLrpFL+Mo0LrwFb85wm/oG3rbdrobXpMkP iOk37oA2yui+b5kNKHE67uICNz5D3EGVyePcEnIBjSIQWZhBUXoMxre9ttYeSJ3G6mya plj47Sd0Tc3LE81JFKREMNt6i/NwxhROigeXVk1XBohi1UNeNqXFvHQjCOv3F1o0+WCI 3Aa09dxhgJ9E+JCKG200C8jrT34/Qx3jkE4lYobV2izzroiwYAhQot2UIvSj6ZiCwNUP nF4Z+cPdOgHIApVGKw4NyqDMQeEy9muy8on2Y36yhZzStwob421Jqr6u/uZcgFAKknLP jAfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9-v6si10298895pla.32.2018.04.22.09.03.11; Sun, 22 Apr 2018 09:03:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754121AbeDVN6T (ORCPT + 99 others); Sun, 22 Apr 2018 09:58:19 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46104 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754104AbeDVN6M (ORCPT ); Sun, 22 Apr 2018 09:58:12 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 63B2FCD5; Sun, 22 Apr 2018 13:58:11 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steve French , Pavel Shilovsky Subject: [PATCH 4.16 050/196] smb3: Fix root directory when server returns inode number of zero Date: Sun, 22 Apr 2018 15:51:10 +0200 Message-Id: <20180422135106.677589103@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Steve French commit 7ea884c77e5c97f1e0a1a422d961d27f78ca2745 upstream. Some servers return inode number zero for the root directory, which causes ls to display incorrect data (missing "." and ".."). If the server returns zero for the inode number of the root directory, fake an inode number for it. Signed-off-by: Steve French Reviewed-by: Pavel Shilovsky CC: Stable Signed-off-by: Greg Kroah-Hartman --- fs/cifs/cifsglob.h | 1 + fs/cifs/inode.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -1466,6 +1466,7 @@ struct dfs_info3_param { #define CIFS_FATTR_NEED_REVAL 0x4 #define CIFS_FATTR_INO_COLLISION 0x8 #define CIFS_FATTR_UNKNOWN_NLINK 0x10 +#define CIFS_FATTR_FAKE_ROOT_INO 0x20 struct cifs_fattr { u32 cf_flags; --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -707,6 +707,18 @@ cgfi_exit: return rc; } +/* Simple function to return a 64 bit hash of string. Rarely called */ +static __u64 simple_hashstr(const char *str) +{ + const __u64 hash_mult = 1125899906842597L; /* a big enough prime */ + __u64 hash = 0; + + while (*str) + hash = (hash + (__u64) *str++) * hash_mult; + + return hash; +} + int cifs_get_inode_info(struct inode **inode, const char *full_path, FILE_ALL_INFO *data, struct super_block *sb, int xid, @@ -816,6 +828,14 @@ cifs_get_inode_info(struct inode **inode tmprc); fattr.cf_uniqueid = iunique(sb, ROOT_I); cifs_autodisable_serverino(cifs_sb); + } else if ((fattr.cf_uniqueid == 0) && + strlen(full_path) == 0) { + /* some servers ret bad root ino ie 0 */ + cifs_dbg(FYI, "Invalid (0) inodenum\n"); + fattr.cf_flags |= + CIFS_FATTR_FAKE_ROOT_INO; + fattr.cf_uniqueid = + simple_hashstr(tcon->treeName); } } } else @@ -832,6 +852,16 @@ cifs_get_inode_info(struct inode **inode &fattr.cf_uniqueid, data); if (tmprc) fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid; + else if ((fattr.cf_uniqueid == 0) && + strlen(full_path) == 0) { + /* + * Reuse existing root inode num since + * inum zero for root causes ls of . and .. to + * not be returned + */ + cifs_dbg(FYI, "Srv ret 0 inode num for root\n"); + fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid; + } } else fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid; } @@ -893,6 +923,9 @@ cifs_get_inode_info(struct inode **inode } cgii_exit: + if ((*inode) && ((*inode)->i_ino == 0)) + cifs_dbg(FYI, "inode number of zero returned\n"); + kfree(buf); cifs_put_tlink(tlink); return rc;