Received: by 10.192.165.148 with SMTP id m20csp2488682imm; Sun, 22 Apr 2018 08:04:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx48gdM3THdo/kVn1NMnedGu7sDwCwoAOQywe6NcQPEX4XrXFV7wvI6cd8K9rUkCndSlknDXl X-Received: by 2002:a17:902:b60f:: with SMTP id b15-v6mr18001961pls.12.1524409491121; Sun, 22 Apr 2018 08:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524409491; cv=none; d=google.com; s=arc-20160816; b=M4s+0qYoM6qeZvJGorTDYzi0nx6vcuBphA4amL4BUQ9YBBgrSAj377Hi0i4QllqcIB 5iGN8M2KeW3F2Osp58/4Vcc/ZSPiPIRe8cfi5yhpTYfV7oHOBxsA8zfRrNmD7I7U2x6j 56MEJdIRe349OtZZRvGxJcOaSFmQP6pR5EDT3stzJ3jRPGuT9GyNvhdCOijFF2rIyxyC w//xC0sP6lWHcPfrtKA1F9F6gdDINeqkk7MrWWqFpMJ1EGpbFacv+tx1t+qYpscQrFpn K5IQrwvcu5s/P4tVrAziOL2KrXK1LQz9jEYDk5SPU+9Qcx1ThmtvrwldGVYvIhhrbGSZ KsKQ== 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=fnCS6fKF6zpqy6wW8y9iP93qzhumWVJL69bww14oHhQ=; b=QLUX1/sGb1IYONu7Bt3ijcxkIet0bF1Opkv+Ci7PK/eOgLH5I2KVQwj0GISAZkq9PB wXx7u+YzSNIhKfTwjiX5L5GPnlR+fkYv4XIsrPFrrwlmsmLbfPS4YOzuc7zp+0Q32e+W oj5PEIvl1VgaNcZtodGaTaalPYuBH+qg/bIGt3aTJ0I8Y3wbbfLeQqKP2dcHK9eMrKnP /NbY9I+F2+Ff/MHmHqC+XLd7odJl8kIJ0DeJkkYxFJnSvRueJWxL7c/iApDX4LHW63Ov fpEh4t1k/AjqaRT5CNbST5+dezWBHB1QH0Ef6VjX1Chz1LjCiuDCS/kzkmF6CRYVF3zP Wz1w== 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 v72si9516985pfa.59.2018.04.22.08.04.36; Sun, 22 Apr 2018 08:04:51 -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 S1754871AbeDVPC1 (ORCPT + 99 others); Sun, 22 Apr 2018 11:02:27 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55142 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756702AbeDVOMf (ORCPT ); Sun, 22 Apr 2018 10:12:35 -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 87B37CCE; Sun, 22 Apr 2018 14:12:33 +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.9 23/95] smb3: Fix root directory when server returns inode number of zero Date: Sun, 22 Apr 2018 15:52:52 +0200 Message-Id: <20180422135211.388104900@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@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.9-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 @@ -1412,6 +1412,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 @@ -701,6 +701,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, @@ -810,6 +822,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 @@ -826,6 +846,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; } @@ -887,6 +917,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;