Skip to content

Commit 81dc1e4

Browse files
committed
Merge tag 'v7.1-rc1-part1-smb3-client-fixes' of git://git.samba.org/sfrench/cifs-2.6
Pull smb client updates from Steve French: - Fix EAs bounds check - Fix OOB read in symlink response parsing - Add support for creating tmpfiles - Minor debug improvement for mount failure - Minor crypto cleanup - Add missing module description - mount fix for lease vs. nolease - Add Metze as maintainer for smbdirect - Minor error mapping header cleanup - Improve search speed of SMB1 maperror - Fix potential null ptr ref in smb2 map error tests * tag 'v7.1-rc1-part1-smb3-client-fixes' of git://git.samba.org/sfrench/cifs-2.6: (26 commits) smb: client: allow both 'lease' and 'nolease' mount options smb: client: get rid of d_drop()+d_add() smb: client: set ATTR_TEMPORARY with O_TMPFILE | O_EXCL smb: client: add support for O_TMPFILE vfs: introduce d_mark_tmpfile_name() MAINTAINERS: create entry for smbdirect smb: client: add missing MODULE_DESCRIPTION() to smb1maperror_test smb: client: fix OOB reads parsing symlink error response smb: client: fix off-by-8 bounds check in check_wsl_eas() smb: client: Remove unnecessary selection of CRYPTO_ECB smb/client: move smb2maperror declarations to smb2proto.h smb/client: introduce KUnit tests to check DOS/SRV err mapping search smb/client: check if SMB1 DOS/SRV error mapping arrays are sorted smb/client: use binary search for SMB1 DOS/SRV error mapping smb/client: autogenerate SMB1 DOS/SRV to POSIX error mapping smb/client: annotate smberr.h with POSIX error codes smb/client: move ERRnetlogonNotStarted to DOS error class smb/client: introduce KUnit test to check ntstatus_to_dos_map search smb/client: check if ntstatus_to_dos_map is sorted smb/client: use binary search for NT status to DOS mapping ...
2 parents 0b0128e + 4248ed1 commit 81dc1e4

28 files changed

Lines changed: 1835 additions & 2458 deletions

MAINTAINERS

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24401,6 +24401,20 @@ T: git https://github.com/cschaufler/smack-next.git
2440124401
F: Documentation/admin-guide/LSM/Smack.rst
2440224402
F: security/smack/
2440324403

24404+
SMBDIRECT (RDMA Stream Transport with Read/Write-Offload, MS-SMBD)
24405+
M: Steve French <smfrench@gmail.com>
24406+
M: Steve French <sfrench@samba.org>
24407+
M: Namjae Jeon <linkinjeon@kernel.org>
24408+
M: Namjae Jeon <linkinjeon@samba.org>
24409+
R: Stefan Metzmacher <metze@samba.org>
24410+
R: Tom Talpey <tom@talpey.com>
24411+
L: linux-cifs@vger.kernel.org
24412+
L: samba-technical@lists.samba.org (moderated for non-subscribers)
24413+
S: Maintained
24414+
F: fs/smb/client/smbdirect.*
24415+
F: fs/smb/common/smbdirect/
24416+
F: fs/smb/server/transport_rdma.*
24417+
2440424418
SMC91x ETHERNET DRIVER
2440524419
M: Nicolas Pitre <nico@fluxnic.net>
2440624420
S: Odd Fixes

fs/dcache.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,6 +3196,25 @@ void d_mark_tmpfile(struct file *file, struct inode *inode)
31963196
}
31973197
EXPORT_SYMBOL(d_mark_tmpfile);
31983198

3199+
void d_mark_tmpfile_name(struct file *file, const struct qstr *name)
3200+
{
3201+
struct dentry *dentry = file->f_path.dentry;
3202+
char *dname = dentry->d_shortname.string;
3203+
3204+
BUG_ON(dname_external(dentry));
3205+
BUG_ON(d_really_is_positive(dentry));
3206+
BUG_ON(!d_unlinked(dentry));
3207+
BUG_ON(name->len > DNAME_INLINE_LEN - 1);
3208+
spin_lock(&dentry->d_parent->d_lock);
3209+
spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
3210+
dentry->__d_name.len = name->len;
3211+
memcpy(dname, name->name, name->len);
3212+
dname[name->len] = '\0';
3213+
spin_unlock(&dentry->d_lock);
3214+
spin_unlock(&dentry->d_parent->d_lock);
3215+
}
3216+
EXPORT_SYMBOL(d_mark_tmpfile_name);
3217+
31993218
void d_tmpfile(struct file *file, struct inode *inode)
32003219
{
32013220
struct dentry *dentry = file->f_path.dentry;

fs/smb/client/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
smb1_mapping_table.c
2+
smb1_err_dos_map.c
3+
smb1_err_srv_map.c
14
smb2_mapping_table.c

fs/smb/client/Kconfig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ config CIFS
99
select CRYPTO_AEAD2
1010
select CRYPTO_CCM
1111
select CRYPTO_GCM
12-
select CRYPTO_ECB
1312
select CRYPTO_AES
1413
select CRYPTO_LIB_ARC4
1514
select CRYPTO_LIB_MD5
@@ -217,4 +216,15 @@ config CIFS_COMPRESSION
217216
Say Y here if you want SMB traffic to be compressed.
218217
If unsure, say N.
219218

219+
config SMB1_KUNIT_TESTS
220+
tristate "KUnit tests for SMB1"
221+
depends on SMB_KUNIT_TESTS && CIFS_ALLOW_INSECURE_LEGACY
222+
default SMB_KUNIT_TESTS
223+
help
224+
This builds the SMB1-specific KUnit tests.
225+
226+
These tests are only enabled when legacy insecure SMB1 support
227+
(CIFS_ALLOW_INSECURE_LEGACY) is enabled.
228+
229+
If unsure, say N.
220230
endif

fs/smb/client/Makefile

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ obj-$(CONFIG_CIFS) += cifs.o
77

88
cifs-y := trace.o cifsfs.o cifs_debug.o connect.o dir.o file.o \
99
inode.o link.o misc.o netmisc.o smbencrypt.o transport.o \
10-
cached_dir.o cifs_unicode.o nterr.o cifsencrypt.o \
10+
cached_dir.o cifs_unicode.o cifsencrypt.o \
1111
readdir.o ioctl.o sess.o export.o unc.o winucase.o \
1212
smb2ops.o smb2maperror.o smb2transport.o \
1313
smb2misc.o smb2pdu.o smb2inode.o smb2file.o cifsacl.o fs_context.o \
@@ -44,6 +44,26 @@ cifs-$(CONFIG_CIFS_ALLOW_INSECURE_LEGACY) += \
4444

4545
cifs-$(CONFIG_CIFS_COMPRESSION) += compress.o compress/lz77.o
4646

47+
ifneq ($(CONFIG_CIFS_ALLOW_INSECURE_LEGACY),)
48+
#
49+
# Build the SMB1 error mapping tables from nterr.h and smberr.h
50+
#
51+
smb1-gen-y := smb1_mapping_table.c \
52+
smb1_err_dos_map.c \
53+
smb1_err_srv_map.c
54+
55+
$(obj)/smb1_mapping_table.c: $(src)/nterr.h $(src)/gen_smb1_mapping FORCE
56+
$(call if_changed,gen_smb1_mapping)
57+
58+
$(obj)/smb1_err_%.c: $(src)/smberr.h $(src)/gen_smb1_mapping FORCE
59+
$(call if_changed,gen_smb1_mapping)
60+
61+
$(obj)/smb1maperror.o: $(addprefix $(obj)/, $(smb1-gen-y))
62+
63+
quiet_cmd_gen_smb1_mapping = GEN $@
64+
cmd_gen_smb1_mapping = perl $(src)/gen_smb1_mapping $< $@
65+
endif
66+
4767
#
4868
# Build the SMB2 error mapping table from smb2status.h
4969
#
@@ -56,7 +76,8 @@ $(obj)/smb2maperror.o: $(obj)/smb2_mapping_table.c
5676
quiet_cmd_gen_smb2_mapping = GEN $@
5777
cmd_gen_smb2_mapping = perl $(src)/gen_smb2_mapping $< $@
5878

79+
obj-$(CONFIG_SMB1_KUNIT_TESTS) += smb1maperror_test.o
5980
obj-$(CONFIG_SMB_KUNIT_TESTS) += smb2maperror_test.o
6081

6182
# Let Kbuild handle tracking and cleaning
62-
targets += smb2_mapping_table.c
83+
targets += smb2_mapping_table.c $(smb1-gen-y)

fs/smb/client/cifsfs.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ MODULE_PARM_DESC(dir_cache_timeout, "Number of seconds to cache directory conten
124124
/* Module-wide total cached dirents (in bytes) across all tcons */
125125
atomic64_t cifs_dircache_bytes_used = ATOMIC64_INIT(0);
126126

127+
atomic_t cifs_sillycounter;
128+
atomic_t cifs_tmpcounter;
129+
127130
/*
128131
* Write-only module parameter to drop all cached directory entries across
129132
* all CIFS mounts. Echo a non-zero value to trigger.
@@ -1199,6 +1202,7 @@ MODULE_ALIAS("smb3");
11991202
const struct inode_operations cifs_dir_inode_ops = {
12001203
.create = cifs_create,
12011204
.atomic_open = cifs_atomic_open,
1205+
.tmpfile = cifs_tmpfile,
12021206
.lookup = cifs_lookup,
12031207
.getattr = cifs_getattr,
12041208
.unlink = cifs_unlink,
@@ -1911,6 +1915,12 @@ init_cifs(void)
19111915
{
19121916
int rc = 0;
19131917

1918+
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
1919+
rc = smb1_init_maperror();
1920+
if (rc)
1921+
return rc;
1922+
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
1923+
19141924
rc = smb2_init_maperror();
19151925
if (rc)
19161926
return rc;
@@ -2148,7 +2158,6 @@ MODULE_DESCRIPTION
21482158
("VFS to access SMB3 servers e.g. Samba, Macs, Azure and Windows (and "
21492159
"also older servers complying with the SNIA CIFS Specification)");
21502160
MODULE_VERSION(CIFS_VERSION);
2151-
MODULE_SOFTDEP("ecb");
21522161
MODULE_SOFTDEP("nls");
21532162
MODULE_SOFTDEP("aes");
21542163
MODULE_SOFTDEP("cmac");

fs/smb/client/cifsfs.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
#define ROOT_I 2
1515

16+
extern atomic_t cifs_sillycounter;
17+
extern atomic_t cifs_tmpcounter;
18+
1619
/*
1720
* ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
1821
* so that it will fit. We use hash_64 to convert the value to 31 bits, and
@@ -49,10 +52,12 @@ void cifs_sb_deactive(struct super_block *sb);
4952
/* Functions related to inodes */
5053
extern const struct inode_operations cifs_dir_inode_ops;
5154
struct inode *cifs_root_iget(struct super_block *sb);
52-
int cifs_create(struct mnt_idmap *idmap, struct inode *inode,
55+
int cifs_create(struct mnt_idmap *idmap, struct inode *dir,
5356
struct dentry *direntry, umode_t mode, bool excl);
54-
int cifs_atomic_open(struct inode *inode, struct dentry *direntry,
57+
int cifs_atomic_open(struct inode *dir, struct dentry *direntry,
5558
struct file *file, unsigned int oflags, umode_t mode);
59+
int cifs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
60+
struct file *file, umode_t mode);
5661
struct dentry *cifs_lookup(struct inode *parent_dir_inode,
5762
struct dentry *direntry, unsigned int flags);
5863
int cifs_unlink(struct inode *dir, struct dentry *dentry);
@@ -142,6 +147,20 @@ struct smb3_fs_context;
142147
struct dentry *cifs_smb3_do_mount(struct file_system_type *fs_type, int flags,
143148
struct smb3_fs_context *old_ctx);
144149

150+
char *cifs_silly_fullpath(struct dentry *dentry);
151+
152+
#define CIFS_TMPNAME_PREFIX ".__smbfile_tmp"
153+
#define CIFS_TMPNAME_PREFIX_LEN ((int)sizeof(CIFS_TMPNAME_PREFIX) - 1)
154+
#define CIFS_TMPNAME_COUNTER_LEN ((int)sizeof(cifs_tmpcounter) * 2)
155+
#define CIFS_TMPNAME_LEN \
156+
(CIFS_TMPNAME_PREFIX_LEN + CIFS_TMPNAME_COUNTER_LEN)
157+
158+
#define CIFS_SILLYNAME_PREFIX ".__smbfile_silly"
159+
#define CIFS_SILLYNAME_PREFIX_LEN ((int)sizeof(CIFS_SILLYNAME_PREFIX) - 1)
160+
#define CIFS_SILLYNAME_COUNTER_LEN ((int)sizeof(cifs_sillycounter) * 2)
161+
#define CIFS_SILLYNAME_LEN \
162+
(CIFS_SILLYNAME_PREFIX_LEN + CIFS_SILLYNAME_COUNTER_LEN)
163+
145164
#ifdef CONFIG_CIFS_NFSD_EXPORT
146165
extern const struct export_operations cifs_export_ops;
147166
#endif /* CONFIG_CIFS_NFSD_EXPORT */

fs/smb/client/cifsglob.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,9 +1534,16 @@ int cifs_file_set_size(const unsigned int xid, struct dentry *dentry,
15341534
#define CIFS_CACHE_RW_FLG (CIFS_CACHE_READ_FLG | CIFS_CACHE_WRITE_FLG)
15351535
#define CIFS_CACHE_RHW_FLG (CIFS_CACHE_RW_FLG | CIFS_CACHE_HANDLE_FLG)
15361536

1537-
/*
1538-
* One of these for each file inode
1539-
*/
1537+
enum cifs_inode_flags {
1538+
CIFS_INODE_PENDING_OPLOCK_BREAK, /* oplock break in progress */
1539+
CIFS_INODE_PENDING_WRITERS, /* Writes in progress */
1540+
CIFS_INODE_FLAG_UNUSED, /* Unused flag */
1541+
CIFS_INO_DELETE_PENDING, /* delete pending on server */
1542+
CIFS_INO_INVALID_MAPPING, /* pagecache is invalid */
1543+
CIFS_INO_LOCK, /* lock bit for synchronization */
1544+
CIFS_INO_TMPFILE, /* for O_TMPFILE inodes */
1545+
CIFS_INO_CLOSE_ON_LOCK, /* Not to defer the close when lock is set */
1546+
};
15401547

15411548
struct cifsInodeInfo {
15421549
struct netfs_inode netfs; /* Netfslib context and vfs inode */
@@ -1554,13 +1561,6 @@ struct cifsInodeInfo {
15541561
__u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
15551562
unsigned int oplock; /* oplock/lease level we have */
15561563
__u16 epoch; /* used to track lease state changes */
1557-
#define CIFS_INODE_PENDING_OPLOCK_BREAK (0) /* oplock break in progress */
1558-
#define CIFS_INODE_PENDING_WRITERS (1) /* Writes in progress */
1559-
#define CIFS_INODE_FLAG_UNUSED (2) /* Unused flag */
1560-
#define CIFS_INO_DELETE_PENDING (3) /* delete pending on server */
1561-
#define CIFS_INO_INVALID_MAPPING (4) /* pagecache is invalid */
1562-
#define CIFS_INO_LOCK (5) /* lock bit for synchronization */
1563-
#define CIFS_INO_CLOSE_ON_LOCK (7) /* Not to defer the close when lock is set */
15641564
unsigned long flags;
15651565
spinlock_t writers_lock;
15661566
unsigned int writers; /* Number of writers on this inode */
@@ -2259,6 +2259,7 @@ struct smb2_compound_vars {
22592259
struct kvec qi_iov;
22602260
struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
22612261
struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
2262+
struct kvec hl_iov[SMB2_SET_INFO_IOV_SIZE];
22622263
struct kvec unlink_iov[SMB2_SET_INFO_IOV_SIZE];
22632264
struct kvec rename_iov[SMB2_SET_INFO_IOV_SIZE];
22642265
struct kvec close_iov;
@@ -2383,6 +2384,8 @@ static inline int cifs_open_create_options(unsigned int oflags, int opts)
23832384
opts |= CREATE_WRITE_THROUGH;
23842385
if (oflags & O_DIRECT)
23852386
opts |= CREATE_NO_BUFFER;
2387+
if (oflags & O_TMPFILE)
2388+
opts |= CREATE_DELETE_ON_CLOSE;
23862389
return opts;
23872390
}
23882391

fs/smb/client/cifsproto.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode,
141141
int __cifs_get_writable_file(struct cifsInodeInfo *cifs_inode,
142142
unsigned int find_flags, unsigned int open_flags,
143143
struct cifsFileInfo **ret_file);
144-
int cifs_get_writable_path(struct cifs_tcon *tcon, const char *name, int flags,
144+
int cifs_get_writable_path(struct cifs_tcon *tcon, const char *name,
145+
struct inode *inode, int flags,
145146
struct cifsFileInfo **ret_file);
146147
struct cifsFileInfo *__find_readable_file(struct cifsInodeInfo *cifs_inode,
147148
unsigned int find_flags,

0 commit comments

Comments
 (0)