nfsd4: ensure cm_xid does not change across userspace fetches
Subsystems (2)
PATCH 1/1 nfsd4: ensure cm_xid does not change across userspace fetches
cld_pipe_downcall() has two fetches from an overapped userspace memory. The first fetch copy_from_user(&xid, &cmsg->cm_xid, sizeof(xid)) get the xid and use xid to lookup the parent struct cld_upcall *cup. The second fetch copy_from_user(&cup->cu_msg, src, mlen) place the whole message into &cup->cu_msg.
Since the userspace thread has full control over this &cmsg->cm_xid, it can race condition to change the cm_xid value across the two fetches, (say, change from 1 to 2), therefore, de-listing the cup with cu_msg.cm_xid == 1 but later put cu_msg.cm_xid = 2.
Whether this double-fetch situation is a security critical bug depends on how cup->cu_msg is used later. However, given that it is hard to enumerate all the possible use cases, a safer way might be to ensure that the xid does not change across the fetches, which is what this patch is for.
--- fs/nfsd/nfs4recover.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/nfsd/nfs4recover.c +5 -0
@@ -753,6 +753,11 @@ cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)if (copy_from_user (&cup->cu_msg, src, mlen) !=0 )return -EFAULT ; +/* ensure that the xid has not been changed */ +if (cup->cu_msg.cm_xid != xid) { +return -EFAULT ; + } +wake_up_process (cup->cu_task);return mlen; }
Signature · 1 line
2.7.4
Quoted 11 lines · Meng Xu
cld_pipe_downcall()has two fetches from an overapped userspace memory. The first fetchcopy_from_user(&xid, &cmsg->cm_xid, sizeof(xid))get the xid and use xid to lookup the parent structcld_upcall*cup. The second fetchcopy_from_user(&cup->cu_msg, src, mlen)place the whole message into&cup->cu_msg.Since the userspace thread has full control over this
&cmsg->cm_xid, it can race condition to change thecm_xidvalue across the two fetches, (say, change from 1 to 2), therefore, de-listing the cup with cu_msg.cm_xid == 1 but later put cu_msg.cm_xid = 2.
Quoted 5 lines
Whether this double-fetch situation is a security critical bug depends on how
cup->cu_msgis used later. However, given that it is hard to enumerate all the possible use cases, a safer way might be to ensure that the xid does not change across the fetches, which is what this patch is for.
Alternatively, couldn't we copy the whole message just once at the start? It doesn't look like there very large, so there's room for it on the stack, if that's the problem.
--b.
Quoted 24 lines
Signed-off-by Meng Xu <[email protected]>--- fs/nfsd/nfs4recover.c | 5 +++++ 1 file changed, 5 insertions(+)fs/nfsd/nfs4recover.c +5
-0@@ -753,6 +753,11 @@ cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)if (copy_from_user (&cup->cu_msg, src, mlen) !=0 )return -EFAULT ; +/* ensure that the xid has not been changed */ +if (cup->cu_msg.cm_xid != xid) { +return -EFAULT ; + } +wake_up_process (cup->cu_task);return mlen; }Signature · 1 line
2.7.4
Quoted 18 lines · J. Bruce Fields
Quoted 11 lines · Meng Xu
cld_pipe_downcall()has two fetches from an overapped userspace memory. The first fetchcopy_from_user(&xid, &cmsg->cm_xid, sizeof(xid))get the xid and use xid to lookup the parent structcld_upcall*cup. The second fetchcopy_from_user(&cup->cu_msg, src, mlen)place the whole message into&cup->cu_msg.Since the userspace thread has full control over this
&cmsg->cm_xid, it can race condition to change thecm_xidvalue across the two fetches, (say, change from 1 to 2), therefore, de-listing the cup with cu_msg.cm_xid == 1 but later put cu_msg.cm_xid = 2.Quoted 5 lines
Whether this double-fetch situation is a security critical bug depends on how
cup->cu_msgis used later. However, given that it is hard to enumerate all the possible use cases, a safer way might be to ensure that the xid does not change across the fetches, which is what this patch is for.
Quoted 3 lines
Alternatively, couldn't we copy the whole message just once at the start? It doesn't look like there very large, so there's room for it on the stack, if that's the problem.
Well, I'm bikeshedding, your version's OK.
I'm not convinced there's really a bug, though: as far as I can tell we *only* use the xid for matching call and response, so if it's changed it doesn't affect what any later code does.
--b.
Quoted 27 lines
--b.
Quoted 24 lines
Signed-off-by Meng Xu <[email protected]>--- fs/nfsd/nfs4recover.c | 5 +++++ 1 file changed, 5 insertions(+)fs/nfsd/nfs4recover.c +5
-0@@ -753,6 +753,11 @@ cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)if (copy_from_user (&cup->cu_msg, src, mlen) !=0 )return -EFAULT ; +/* ensure that the xid has not been changed */ +if (cup->cu_msg.cm_xid != xid) { +return -EFAULT ; + } +wake_up_process (cup->cu_task);return mlen; }Signature · 1 line
2.7.4