linux/fs/cifs
Thiago Rafael Becker 6efa994e35 cifs: retry lookup and readdir when EAGAIN is returned.
According to the investigation performed by Jacob Shivers at Red Hat,
cifs_lookup and cifs_readdir leak EAGAIN when the user session is
deleted on the server. Fix this issue by implementing a retry with
limits, as is implemented in cifs_revalidate_dentry_attr.

Reproducer based on the work by Jacob Shivers:

  ~~~
  $ cat readdir-cifs-test.sh
  #!/bin/bash

  # Install and configure powershell and sshd on the windows
  #  server as descibed in
  # https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_overview
  # This script uses expect(1)

  USER=dude
  SERVER=192.168.0.2
  RPATH=root
  PASS='password'

  function debug_funcs {
  	for line in $@ ; do
  		echo "func $line +p" > /sys/kernel/debug/dynamic_debug/control
  	done
  }

  function setup {
  	echo 1 > /proc/fs/cifs/cifsFYI
  	debug_funcs wait_for_compound_request \
                smb2_query_dir_first cifs_readdir \
                compound_send_recv cifs_reconnect_tcon \
                generic_ip_connect cifs_reconnect \
                smb2_reconnect_server smb2_reconnect \
                cifs_readv_from_socket cifs_readv_receive
  	tcpdump -i eth0 -w cifs.pcap host 192.168.2.182 & sleep 5
  	dmesg -C
  }

  function test_call {
  	if [[ $1 == 1 ]] ; then
  		tracer="strace -tt -f -s 4096 -o trace-$(date -Iseconds).txt"
  	fi
        # Change the command here to anything appropriate
  	$tracer ls $2 > /dev/null
  	res=$?
  	if [[ $1 == 1 ]] ; then
  		if [[ $res == 0 ]] ; then
  			1>&2 echo success
  		else
  			1>&2 echo "failure ($res)"
  		fi
  	fi
  }

  mountpoint /mnt > /dev/null || mount -t cifs -o username=$USER,pass=$PASS //$SERVER/$RPATH /mnt

  test_call 0 /mnt/

  /usr/bin/expect << EOF
  	set timeout 60

  	spawn ssh $USER@$SERVER

  	expect "yes/no" {
  		send "yes\r"
  		expect "*?assword" { send "$PASS\r" }
  	} "*?assword" { send "$PASS\r" }

  	expect ">" { send "powershell close-smbsession -force\r" }
  	expect ">" { send "exit\r" }
  	expect eof
  EOF

  sysctl -w vm.drop_caches=2 > /dev/null
  sysctl -w vm.drop_caches=2 > /dev/null

  setup

  test_call 1 /mnt/
  ~~~

Signed-off-by: Thiago Rafael Becker <trbecker@gmail.com>
Acked-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
2021-06-20 21:28:17 -05:00
..
asn1.c cifs: decoding negTokenInit with generic ASN1 decoder 2021-06-20 21:28:17 -05:00
cache.c cifs: Make extract_sharename function public 2020-12-14 09:16:22 -06:00
cifs_debug.c cifs: export supported mount options via new mount_params /proc file 2021-04-25 16:28:24 -05:00
cifs_debug.h cifs: Standardize logging output 2020-06-01 00:10:18 -05:00
cifs_dfs_ref.c cifs: fix doc warnings in cifs_dfs_ref.c 2021-06-20 21:28:16 -05:00
cifs_fs_sb.h cifs: handle different charsets in dfs cache 2021-06-20 21:28:16 -05:00
cifs_ioctl.h cifs: change format of CIFS_FULL_KEY_DUMP ioctl 2021-05-27 15:26:32 -05:00
cifs_spnego.c cifs: switch servers depending on binding state 2019-11-25 01:16:30 -06:00
cifs_spnego.h
cifs_spnego_negtokeninit.asn1 cifs: decoding negTokenInit with generic ASN1 decoder 2021-06-20 21:28:17 -05:00
cifs_swn.c fs/cifs/: fix misspellings using codespell tool 2021-03-19 00:37:51 -05:00
cifs_swn.h cifs: simplify SWN code with dummy funcs instead of ifdefs 2021-04-25 16:28:22 -05:00
cifs_unicode.c Convert trailing spaces and periods in path components 2020-10-11 23:57:18 -05:00
cifs_unicode.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
cifs_uniupr.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
cifsacl.c cifs: Remove useless variable 2021-04-25 16:28:22 -05:00
cifsacl.h cifs: Fix cifsacl ACE mask for group and others. 2021-02-22 21:20:44 -06:00
cifsencrypt.c cifs: change confusing field serverName (to ip_addr) 2021-02-22 21:20:43 -06:00
cifsfs.c Fix kernel oops when CONFIG_DEBUG_ATOMIC_SLEEP is enabled. 2021-05-19 21:11:26 -05:00
cifsfs.h cifs: update internal version number 2021-04-25 23:59:27 -05:00
cifsglob.h cifs: handle different charsets in dfs cache 2021-06-20 21:28:16 -05:00
cifspdu.h cifs: change format of CIFS_FULL_KEY_DUMP ioctl 2021-05-27 15:26:32 -05:00
cifsproto.h 10 CIFS/SMB3 changesets including some important multichannel fixes, as well as support for handle leases (deferred close) and shutdown support 2021-05-05 13:37:07 -07:00
cifsroot.c cifs: Standardize logging output 2020-06-01 00:10:18 -05:00
cifssmb.c cifs: remove redundant initialization of variable rc 2021-06-20 21:28:16 -05:00
connect.c cifs: do not share tcp servers with dfs mounts 2021-06-20 21:28:17 -05:00
dfs_cache.c cifs: fix check of dfs interlinks 2021-06-20 21:28:17 -05:00
dfs_cache.h cifs: handle different charsets in dfs cache 2021-06-20 21:28:16 -05:00
dir.c cifs: retry lookup and readdir when EAGAIN is returned. 2021-06-20 21:28:17 -05:00
dns_resolve.c keys: Pass the network namespace into request_key mechanism 2019-06-27 23:02:12 +01:00
dns_resolve.h
export.c docs: fs: convert docs without extension to ReST 2019-07-31 13:31:05 -06:00
file.c Fix KASAN identified use-after-free issue. 2021-05-20 12:20:42 -05:00
fs_context.c cifs: Fix inconsistent indenting 2021-05-19 21:11:09 -05:00
fs_context.h smb3: add rasize mount parameter to improve readahead performance 2021-04-25 23:59:08 -05:00
fscache.c cifs: Make extract_sharename function public 2020-12-14 09:16:22 -06:00
fscache.h cifs: Make extract_sharename function public 2020-12-14 09:16:22 -06:00
inode.c 10 CIFS/SMB3 changesets including some important multichannel fixes, as well as support for handle leases (deferred close) and shutdown support 2021-05-05 13:37:07 -07:00
ioctl.c cifs: change format of CIFS_FULL_KEY_DUMP ioctl 2021-05-27 15:26:32 -05:00
Kconfig cifs: decoding negTokenInit with generic ASN1 decoder 2021-06-20 21:28:17 -05:00
link.c fs/cifs: Fix resource leak 2021-05-04 11:53:15 -05:00
Makefile cifs: decoding negTokenInit with generic ASN1 decoder 2021-06-20 21:28:17 -05:00
misc.c Fix KASAN identified use-after-free issue. 2021-05-20 12:20:42 -05:00
netlink.c cifs: Constify static struct genl_ops 2021-06-20 21:28:16 -05:00
netlink.h cifs: Register generic netlink family 2020-12-14 09:16:22 -06:00
netmisc.c cifs`: handle ERRBaduid for SMB1 2020-08-02 18:00:25 -05:00
nterr.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 61 2019-05-24 17:36:45 +02:00
nterr.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 61 2019-05-24 17:36:45 +02:00
ntlmssp.h cifs: dynamic allocation of ntlmssp blob 2016-06-23 23:45:07 -05:00
readdir.c Merge branch 'work.inode-type-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2021-04-27 10:57:42 -07:00
rfc1002pdu.h
sess.c cifs: fix ipv6 formating in cifs_ses_add_channel 2021-06-20 21:28:16 -05:00
smb1ops.c cifs: constify path argument of ->make_node() 2021-04-25 16:28:23 -05:00
smb2file.c cifs: allow unlock flock and OFD lock across fork 2020-03-22 22:49:09 -05:00
smb2glob.h cifs: Adjust key sizes and key generation routines for AES256 encryption 2021-03-26 07:49:39 -05:00
smb2inode.c cifs: rename the *_shroot* functions to *_cached_dir* 2021-04-25 16:28:23 -05:00
smb2maperror.c cifs: map STATUS_ACCOUNT_LOCKED_OUT to -EACCES 2020-10-15 23:58:14 -05:00
smb2misc.c cifs: add a timestamp to track when the lease of the cached dir was taken 2021-04-25 16:28:23 -05:00
smb2ops.c cifs: retry lookup and readdir when EAGAIN is returned. 2021-06-20 21:28:17 -05:00
smb2pdu.c cifs: set server->cipher_type to AES-128-CCM for SMB3.0 2021-05-27 14:03:47 -05:00
smb2pdu.h SMB3: update structures for new compression protocol definitions 2021-04-25 16:28:23 -05:00
smb2proto.h cifs: remove duplicated prototype 2021-06-20 21:28:16 -05:00
smb2status.h cifs: don't use __constant_cpu_to_le32() 2019-05-07 23:24:54 -05:00
smb2transport.c cifs: missed ref-counting smb session in find 2021-06-20 21:28:17 -05:00
smbdirect.c cifs: Fix fall-through warnings for Clang 2020-12-13 19:12:07 -06:00
smbdirect.h cifs: smbd: Do not schedule work to send immediate packet on every receive 2020-04-07 12:41:16 -05:00
smbencrypt.c fs: cifs: move from the crypto cipher API to the new DES library interface 2019-08-22 14:57:34 +10:00
smberr.h
smbfsctl.h smb3: add some missing definitions from MS-FSCC 2020-10-23 15:38:10 -05:00
trace.c smb3: Cleanup license mess 2019-01-24 09:37:33 -06:00
trace.h cifs: fix string declarations and assignments in tracepoints 2021-05-27 14:04:32 -05:00
transport.c cifs: Fix preauth hash corruption 2021-03-14 18:14:32 -05:00
unc.c cifs: don't cargo-cult strndup() 2021-04-25 16:28:23 -05:00
winucase.c Replace HTTP links with HTTPS ones: CIFS 2020-07-05 14:23:38 -06:00
xattr.c cifs: add shutdown support 2021-05-03 11:21:22 -05:00