summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Wellving <andreas.wellving@enea.com>2019-05-22 10:02:58 +0200
committerAdrian Mangeac <Adrian.Mangeac@enea.com>2019-05-22 11:52:12 +0200
commitd7718a606abe9feb449eb74c35790d10fe99d696 (patch)
tree29da46a7625a36eb6e887a0679b775ae6772cef2
parentc998841ae1e763fbfa4b00b009114f18146bbe18 (diff)
downloadenea-kernel-cache-d7718a606abe9feb449eb74c35790d10fe99d696.tar.gz
socket: CVE-2018-12232
socket: close race condition between sock_close() and sockfs_setattr() Reference: https://nvd.nist.gov/vuln/detail/CVE-2018-12232 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-4.14.y&id=91717ffc9057f38a0203a40ef36ae2e482fd7cbe Change-Id: If7db46c2af9d629c5311f5d901943289084566a9 Signed-off-by: Andreas Wellving <andreas.wellving@enea.com>
-rw-r--r--patches/cve/CVE-2018-12232-socket-close-race-condition-between-sock_close-and-s.patch98
1 files changed, 98 insertions, 0 deletions
diff --git a/patches/cve/CVE-2018-12232-socket-close-race-condition-between-sock_close-and-s.patch b/patches/cve/CVE-2018-12232-socket-close-race-condition-between-sock_close-and-s.patch
new file mode 100644
index 0000000..2dabfe5
--- /dev/null
+++ b/patches/cve/CVE-2018-12232-socket-close-race-condition-between-sock_close-and-s.patch
@@ -0,0 +1,98 @@
1From 91717ffc9057f38a0203a40ef36ae2e482fd7cbe Mon Sep 17 00:00:00 2001
2From: Cong Wang <xiyou.wangcong@gmail.com>
3Date: Thu, 7 Jun 2018 13:39:49 -0700
4Subject: [PATCH] socket: close race condition between sock_close() and
5 sockfs_setattr()
6
7[ Upstream commit 6d8c50dcb029872b298eea68cc6209c866fd3e14 ]
8
9fchownat() doesn't even hold refcnt of fd until it figures out
10fd is really needed (otherwise is ignored) and releases it after
11it resolves the path. This means sock_close() could race with
12sockfs_setattr(), which leads to a NULL pointer dereference
13since typically we set sock->sk to NULL in ->release().
14
15As pointed out by Al, this is unique to sockfs. So we can fix this
16in socket layer by acquiring inode_lock in sock_close() and
17checking against NULL in sockfs_setattr().
18
19sock_release() is called in many places, only the sock_close()
20path matters here. And fortunately, this should not affect normal
21sock_close() as it is only called when the last fd refcnt is gone.
22It only affects sock_close() with a parallel sockfs_setattr() in
23progress, which is not common.
24
25CVE: CVE-2018-12232
26Upstream-Status: Backport [https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-4.14.y&id=91717ffc9057f38a0203a40ef36ae2e482fd7cbe]
27
28Fixes: 86741ec25462 ("net: core: Add a UID field to struct sock.")
29Reported-by: shankarapailoor <shankarapailoor@gmail.com>
30Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
31Cc: Lorenzo Colitti <lorenzo@google.com>
32Cc: Al Viro <viro@zeniv.linux.org.uk>
33Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
34Signed-off-by: David S. Miller <davem@davemloft.net>
35Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
36Signed-off-by: Andreas Wellving <andreas.wellving@enea.com>
37---
38 net/socket.c | 18 +++++++++++++++---
39 1 file changed, 15 insertions(+), 3 deletions(-)
40
41diff --git a/net/socket.c b/net/socket.c
42index 43d2f17f5eea..8b2bef6cfe42 100644
43--- a/net/socket.c
44+++ b/net/socket.c
45@@ -538,7 +538,10 @@ static int sockfs_setattr(struct dentry *dentry, struct iattr *iattr)
46 if (!err && (iattr->ia_valid & ATTR_UID)) {
47 struct socket *sock = SOCKET_I(d_inode(dentry));
48
49- sock->sk->sk_uid = iattr->ia_uid;
50+ if (sock->sk)
51+ sock->sk->sk_uid = iattr->ia_uid;
52+ else
53+ err = -ENOENT;
54 }
55
56 return err;
57@@ -588,12 +591,16 @@ EXPORT_SYMBOL(sock_alloc);
58 * an inode not a file.
59 */
60
61-void sock_release(struct socket *sock)
62+static void __sock_release(struct socket *sock, struct inode *inode)
63 {
64 if (sock->ops) {
65 struct module *owner = sock->ops->owner;
66
67+ if (inode)
68+ inode_lock(inode);
69 sock->ops->release(sock);
70+ if (inode)
71+ inode_unlock(inode);
72 sock->ops = NULL;
73 module_put(owner);
74 }
75@@ -608,6 +615,11 @@ void sock_release(struct socket *sock)
76 }
77 sock->file = NULL;
78 }
79+
80+void sock_release(struct socket *sock)
81+{
82+ __sock_release(sock, NULL);
83+}
84 EXPORT_SYMBOL(sock_release);
85
86 void __sock_tx_timestamp(__u16 tsflags, __u8 *tx_flags)
87@@ -1122,7 +1134,7 @@ static int sock_mmap(struct file *file, struct vm_area_struct *vma)
88
89 static int sock_close(struct inode *inode, struct file *filp)
90 {
91- sock_release(SOCKET_I(inode));
92+ __sock_release(SOCKET_I(inode), inode);
93 return 0;
94 }
95
96--
972.20.1
98