linux/fs/nfs
Dave Wysochanski e9c925215d NFSv4: Fix possible 1-byte stack overflow in nfs_idmap_read_and_verify_message
commit d68894800e upstream.

In nfs_idmap_read_and_verify_message there is an incorrect sprintf '%d'
that converts the __u32 'im_id' from struct idmap_msg to 'id_str', which
is a stack char array variable of length NFS_UINT_MAXLEN == 11.
If a uid or gid value is > 2147483647 = 0x7fffffff, the conversion
overflows into a negative value, for example:
crash> p (unsigned) (0x80000000)
$1 = 2147483648
crash> p (signed) (0x80000000)
$2 = -2147483648
The '-' sign is written to the buffer and this causes a 1 byte overflow
when the NULL byte is written, which corrupts kernel stack memory.  If
CONFIG_CC_STACKPROTECTOR_STRONG is set we see a stack-protector panic:

[11558053.616565] Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: ffffffffa05b8a8c
[11558053.639063] CPU: 6 PID: 9423 Comm: rpc.idmapd Tainted: G        W      ------------ T 3.10.0-514.el7.x86_64 #1
[11558053.641990] Hardware name: Red Hat OpenStack Compute, BIOS 1.10.2-3.el7_4.1 04/01/2014
[11558053.644462]  ffffffff818c7bc0 00000000b1f3aec1 ffff880de0f9bd48 ffffffff81685eac
[11558053.646430]  ffff880de0f9bdc8 ffffffff8167f2b3 ffffffff00000010 ffff880de0f9bdd8
[11558053.648313]  ffff880de0f9bd78 00000000b1f3aec1 ffffffff811dcb03 ffffffffa05b8a8c
[11558053.650107] Call Trace:
[11558053.651347]  [<ffffffff81685eac>] dump_stack+0x19/0x1b
[11558053.653013]  [<ffffffff8167f2b3>] panic+0xe3/0x1f2
[11558053.666240]  [<ffffffff811dcb03>] ? kfree+0x103/0x140
[11558053.682589]  [<ffffffffa05b8a8c>] ? idmap_pipe_downcall+0x1cc/0x1e0 [nfsv4]
[11558053.689710]  [<ffffffff810855db>] __stack_chk_fail+0x1b/0x30
[11558053.691619]  [<ffffffffa05b8a8c>] idmap_pipe_downcall+0x1cc/0x1e0 [nfsv4]
[11558053.693867]  [<ffffffffa00209d6>] rpc_pipe_write+0x56/0x70 [sunrpc]
[11558053.695763]  [<ffffffff811fe12d>] vfs_write+0xbd/0x1e0
[11558053.702236]  [<ffffffff810acccc>] ? task_work_run+0xac/0xe0
[11558053.704215]  [<ffffffff811fec4f>] SyS_write+0x7f/0xe0
[11558053.709674]  [<ffffffff816964c9>] system_call_fastpath+0x16/0x1b

Fix this by calling the internally defined nfs_map_numeric_to_string()
function which properly uses '%u' to convert this __u32.  For consistency,
also replace the one other place where snprintf is called.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Reported-by: Stephen Johnston <sjohnsto@redhat.com>
Fixes: cf4ab538f1 ("NFSv4: Fix the string length returned by the idmapper")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
[bwh: Backported to 3.16: adjust filename]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
History 2018-11-20 18:05:07 +00:00
..
blocklayout nfs: merge nfs_pgio_data into _header 2014-10-05 13:41:00 -07:00
filelayout NFSv4.1: nfs4_fl_prepare_ds must be careful about reporting success. 2017-03-16 02:26:38 +00:00
objlayout nfs: merge nfs_pgio_data into _header 2014-10-05 13:41:00 -07:00
cache_lib.c NFS: simplify and clean cache library 2013-02-15 10:43:36 -05:00
cache_lib.h NFS: simplify and clean cache library 2013-02-15 10:43:36 -05:00
callback.c NFSv4.x: Fix a refcount leak in nfs_callback_up_net 2016-11-20 01:17:20 +00:00
callback.h NFS: Add in v4.2 callback operation 2013-06-08 16:20:18 -04:00
callback_proc.c NFSv4.1: Minor optimisation in get_layout_by_fh_locked() 2014-02-19 21:21:06 -05:00
callback_xdr.c NFS: Don't drop CB requests with invalid principals 2016-11-20 01:16:49 +00:00
client.c mount: copy the port field into the cloned nfs_server structure. 2017-11-11 13:33:01 +00:00
delegation.c NFSv4: Don't call put_rpccred() under the rcu_read_lock() 2015-03-18 15:06:08 +00:00
delegation.h NFSv4: Fix races between nfs_remove_bad_delegation() and delegation return 2014-11-27 11:21:45 +00:00
dir.c NFS: Fix a performance regression in readdir 2017-03-16 02:26:27 +00:00
direct.c NFS: commit direct writes even if they fail partially 2018-06-16 22:21:54 +01:00
dns_resolve.c NFS: Enabling v4.2 should not recompile nfsd and lockd 2013-11-19 16:20:40 -05:00
dns_resolve.h NFS: DNS resolver cache per network namespace context introduced 2012-01-31 18:20:26 -05:00
file.c mm: drop vm_ops->remap_pages and generic_file_remap_pages() stub 2018-10-03 04:09:51 +01:00
fscache-index.c NFS: Use the inode->i_version to cache NFSv4 change attribute information 2011-10-18 09:14:34 -07:00
fscache.c NFS: Use i_writecount to control whether to get an fscache cookie in nfs_open() 2013-09-27 18:40:25 +01:00
fscache.h NFS: Use i_writecount to control whether to get an fscache cookie in nfs_open() 2013-09-27 18:40:25 +01:00
getroot.c move d_rcu from overlapping d_child to overlapping d_alias 2015-01-15 10:44:58 +00:00
idmap.c NFSv4: Fix possible 1-byte stack overflow in nfs_idmap_read_and_verify_message 2018-11-20 18:05:07 +00:00
inode.c NFS: Fix attribute cache revalidation 2016-02-02 19:09:06 +00:00
internal.h NFS: Fix 2 use after free issues in the I/O code 2018-06-16 22:21:52 +01:00
iostat.h NFS: Squelch compiler warning in nfs_add_server_stats() 2010-05-14 15:09:31 -04:00
Kconfig nfs: fix pnfs Kconfig defaults 2013-11-15 13:41:43 -05:00
Makefile Push the file layout driver into a subdirectory 2014-05-29 20:21:56 -04:00
mount_clnt.c nfs: have nfs_mount fake up a auth_flavs list when the server didn't provide it 2013-06-28 15:51:51 -04:00
namespace.c nfs: use %p[dD] instead of open-coded (and often racy) equivalents 2013-10-24 23:34:50 -04:00
netns.h NFS: Fix /proc/fs/nfsfs/servers and /proc/fs/nfsfs/volumes 2014-11-03 11:28:21 +00:00
nfs.h NFS: Convert v4 into a module 2012-07-30 19:06:52 -04:00
nfs2super.c NFS: Convert v2 into a module 2012-07-30 19:06:41 -04:00
nfs2xdr.c NFS: Create a common results structure for reads and writes 2014-05-28 18:12:43 -04:00
nfs3acl.c NFSv3: Fix another acl regression 2014-09-05 16:36:42 -07:00
nfs3client.c NFS: Only initialize the ACL client in the v3 case 2012-07-30 19:05:54 -04:00
nfs3proc.c nfs: merge nfs_pgio_data into _header 2014-10-05 13:41:00 -07:00
nfs3super.c nfs: use generic posix ACL infrastructure for v3 Posix ACLs 2014-01-26 08:26:20 -05:00
nfs3xdr.c NFS: Fix size of NFSACL SETACL operations 2015-07-15 10:01:24 +01:00
nfs4_fs.h nfs: merge nfs_pgio_data into _header 2014-10-05 13:41:00 -07:00
nfs4client.c nfs4: start callback_ident at idr 1 2015-12-18 16:06:34 +00:00
nfs4file.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2014-06-12 10:30:18 -07:00
nfs4getroot.c NFSv4: Fix security auto-negotiation 2013-09-07 16:18:30 -04:00
nfs4namespace.c NFSv4: test SECINFO RPC_AUTH_GSS pseudoflavors for support 2014-06-24 18:46:58 -04:00
nfs4proc.c nfs: Fix ugly referral attributes 2018-02-13 18:42:25 +00:00
nfs4renewd.c NFSv4.1: Fix an NFSv4.1 state renewal regression 2014-10-30 09:40:14 -07:00
nfs4session.c NFSv4.1: nfs4_destroy_session must call rpc_destroy_waitqueue 2014-02-01 15:13:39 -05:00
nfs4session.h NFSv4.1: nfs4_destroy_session must call rpc_destroy_waitqueue 2014-02-01 15:13:39 -05:00
nfs4state.c nfs: Fix "Don't increment lock sequence ID after NFS4ERR_MOVED" 2017-03-16 02:27:06 +00:00
nfs4super.c mm + fs: store shadow entries in page cache 2014-04-03 16:21:01 -07:00
nfs4sysctl.c nfs: Do not convert nfs_idmap_cache_timeout to jiffies 2018-06-16 22:21:55 +01:00
nfs4trace.c NFSv4.1: Add tracepoints for debugging slot table operations 2013-08-22 08:58:27 -04:00
nfs4trace.h NFS: Avoid RCU usage in tracepoints 2018-02-13 18:42:24 +00:00
nfs4xdr.c NFSv4: fix getacl head length estimation 2017-06-05 21:17:15 +01:00
nfsroot.c SUNRPC/NFS: Add Kbuild dependencies for NFS_DEBUG/RPC_DEBUG 2012-03-20 13:08:26 -04:00
nfstrace.c NFS: Add event tracing for generic NFS lookups 2013-08-22 08:58:18 -04:00
nfstrace.h NFS: fix the handling of NFS_INO_INVALID_DATA flag in nfs_revalidate_mapping 2014-01-27 15:35:56 -05:00
pagelist.c NFS: Fix 2 use after free issues in the I/O code 2018-06-16 22:21:52 +01:00
pnfs.c nfs/pnfs: fix nfs_direct_req ref leak when i/o falls back to the mds 2018-06-16 22:21:53 +01:00
pnfs.h pnfs: add pnfs_put_lseg_async 2014-10-05 13:41:00 -07:00
pnfs_dev.c hlist: drop the node parameter from iterators 2013-02-27 19:10:24 -08:00
proc.c nfs: merge nfs_pgio_data into _header 2014-10-05 13:41:00 -07:00
read.c nfs: merge nfs_pgio_data into _header 2014-10-05 13:41:00 -07:00
super.c fs: Teach path_connected to handle nfs filesystems with multiple roots. 2018-06-16 22:22:41 +01:00
symlink.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
sysctl.c nfs: convert use of typedef ctl_table to struct ctl_table 2014-06-06 16:08:16 -07:00
unlink.c nfs: emit a fsnotify_nameremove call in sillyrename codepath 2014-03-17 15:14:17 -04:00
write.c NFS: Add a cond_resched() to nfs_commit_release_pages() 2018-06-16 22:21:52 +01:00