android_kernel_oneplus_msm8998/net/sunrpc
NeilBrown 8dc821b9f6 SUNRPC: fix refcounting problems with auth_gss messages.
commit 1cded9d2974fe4fe339fc0ccd6638b80d465ab2c upstream.

There are two problems with refcounting of auth_gss messages.

First, the reference on the pipe->pipe list (taken by a call
to rpc_queue_upcall()) is not counted.  It seems to be
assumed that a message in pipe->pipe will always also be in
pipe->in_downcall, where it is correctly reference counted.

However there is no guaranty of this.  I have a report of a
NULL dereferences in rpc_pipe_read() which suggests a msg
that has been freed is still on the pipe->pipe list.

One way I imagine this might happen is:
- message is queued for uid=U and auth->service=S1
- rpc.gssd reads this message and starts processing.
  This removes the message from pipe->pipe
- message is queued for uid=U and auth->service=S2
- rpc.gssd replies to the first message. gss_pipe_downcall()
  calls __gss_find_upcall(pipe, U, NULL) and it finds the
  *second* message, as new messages are placed at the head
  of ->in_downcall, and the service type is not checked.
- This second message is removed from ->in_downcall and freed
  by gss_release_msg() (even though it is still on pipe->pipe)
- rpc.gssd tries to read another message, and dereferences a pointer
  to this message that has just been freed.

I fix this by incrementing the reference count before calling
rpc_queue_upcall(), and decrementing it if that fails, or normally in
gss_pipe_destroy_msg().

It seems strange that the reply doesn't target the message more
precisely, but I don't know all the details.  In any case, I think the
reference counting irregularity became a measureable bug when the
extra arg was added to __gss_find_upcall(), hence the Fixes: line
below.

The second problem is that if rpc_queue_upcall() fails, the new
message is not freed. gss_alloc_msg() set the ->count to 1,
gss_add_msg() increments this to 2, gss_unhash_msg() decrements to 1,
then the pointer is discarded so the memory never gets freed.

Fixes: 9130b8dbc6ac ("SUNRPC: allow for upcalls for same uid but different gss service")
Link: https://bugzilla.opensuse.org/show_bug.cgi?id=1011250
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-04-21 09:30:08 +02:00
..
auth_gss SUNRPC: fix refcounting problems with auth_gss messages. 2017-04-21 09:30:08 +02:00
xprtrdma svcrdma: avoid duplicate dma unmapping during error recovery 2017-01-26 08:23:48 +01:00
addr.c
auth.c
auth_generic.c
auth_null.c
auth_unix.c
backchannel_rqst.c SUNRPC: Fix callback channel 2015-12-07 13:04:59 -08:00
cache.c sunrpc/cache: drop reference when sunrpc_cache_pipe_upcall() detects a race 2016-05-04 14:48:54 -07:00
clnt.c SUNRPC: cleanup ida information when removing sunrpc module 2017-02-01 08:30:53 +01:00
debugfs.c
Kconfig
Makefile
netns.h
rpc_pipe.c
rpcb_clnt.c
sched.c sched/wait: Fix the signal handling fix 2015-12-13 14:30:59 -08:00
socklib.c
stats.c
sunrpc.h
sunrpc_syms.c SUNRPC: cleanup ida information when removing sunrpc module 2017-02-01 08:30:53 +01:00
svc.c NFS: Don't drop CB requests with invalid principals 2016-10-07 15:23:45 +02:00
svc_xprt.c
svcauth.c
svcauth_unix.c
svcsock.c
sysctl.c
timer.c
xdr.c
xprt.c
xprtsock.c sunrpc: fix write space race causing stalls 2016-10-28 03:01:31 -04:00