|
|
23221e |
From 18c390171a63c1be8df1a62172214efbd9e84813 Mon Sep 17 00:00:00 2001
|
|
|
23221e |
From: Joe Lawrence <joe.lawrence@redhat.com>
|
|
|
23221e |
Date: Thu, 20 Jan 2022 14:39:19 -0500
|
|
|
23221e |
Subject: [KPATCH CVE-2021-0920] af_unix: kpatch fixes for CVE-2021-0920
|
|
|
23221e |
|
|
|
23221e |
Kernels:
|
|
|
23221e |
4.18.0-348.el8
|
|
|
23221e |
4.18.0-348.2.1.el8_5
|
|
|
23221e |
4.18.0-348.7.1.el8_5
|
|
|
23221e |
4.18.0-348.12.2.el8_5
|
|
|
23221e |
|
|
|
23221e |
Changes since last build:
|
|
|
23221e |
arches: x86_64 ppc64le
|
|
|
23221e |
af_unix.o: changed function: unix_dgram_recvmsg
|
|
|
23221e |
af_unix.o: changed function: unix_stream_read_generic
|
|
|
23221e |
---------------------------
|
|
|
23221e |
|
|
|
23221e |
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-8/-/merge_requests/17
|
|
|
23221e |
Approved-by: Yannick Cote (@ycote1)
|
|
|
23221e |
Approved-by: Artem Savkov (@artem.savkov)
|
|
|
23221e |
Kernels:
|
|
|
23221e |
4.18.0-348.el8
|
|
|
23221e |
4.18.0-348.2.1.el8_5
|
|
|
23221e |
4.18.0-348.7.1.el8_5
|
|
|
23221e |
4.18.0-348.12.2.el8_5
|
|
|
23221e |
|
|
|
23221e |
Modifications: none
|
|
|
23221e |
|
|
|
23221e |
commit 49c79494c048e940be91a9454c2f507bc33680fc
|
|
|
23221e |
Author: Patrick Talbert <ptalbert@redhat.com>
|
|
|
23221e |
Date: Mon Jan 10 13:13:05 2022 +0100
|
|
|
23221e |
|
|
|
23221e |
af_unix: fix garbage collect vs MSG_PEEK
|
|
|
23221e |
|
|
|
23221e |
Bugzilla: https://bugzilla.redhat.com/2031974
|
|
|
23221e |
CVE: CVE-2021-0920
|
|
|
23221e |
Y-Commit: 35c0f6eeb4644e87e7f3c1198a9f31b76220053d
|
|
|
23221e |
|
|
|
23221e |
O-CVE: CVE-2021-0920
|
|
|
23221e |
O-Bugzilla: https://bugzilla.redhat.com/2031975
|
|
|
23221e |
Upstream status: main
|
|
|
23221e |
Testing: Sanity only
|
|
|
23221e |
|
|
|
23221e |
commit cbcf01128d0a92e131bd09f1688fe032480b65ca
|
|
|
23221e |
Author: Miklos Szeredi <mszeredi@redhat.com>
|
|
|
23221e |
Date: Wed Jul 28 14:47:20 2021 +0200
|
|
|
23221e |
|
|
|
23221e |
af_unix: fix garbage collect vs MSG_PEEK
|
|
|
23221e |
|
|
|
23221e |
unix_gc() assumes that candidate sockets can never gain an external
|
|
|
23221e |
reference (i.e. be installed into an fd) while the unix_gc_lock is
|
|
|
23221e |
held. Except for MSG_PEEK this is guaranteed by modifying inflight
|
|
|
23221e |
count under the unix_gc_lock.
|
|
|
23221e |
|
|
|
23221e |
MSG_PEEK does not touch any variable protected by unix_gc_lock (file
|
|
|
23221e |
count is not), yet it needs to be serialized with garbage collection.
|
|
|
23221e |
Do this by locking/unlocking unix_gc_lock:
|
|
|
23221e |
|
|
|
23221e |
1) increment file count
|
|
|
23221e |
|
|
|
23221e |
2) lock/unlock barrier to make sure incremented file count is visible
|
|
|
23221e |
to garbage collection
|
|
|
23221e |
|
|
|
23221e |
3) install file into fd
|
|
|
23221e |
|
|
|
23221e |
This is a lock barrier (unlike smp_mb()) that ensures that garbage
|
|
|
23221e |
collection is run completely before or completely after the barrier.
|
|
|
23221e |
|
|
|
23221e |
Cc: <stable@vger.kernel.org>
|
|
|
23221e |
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
|
|
|
23221e |
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
|
|
|
23221e |
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
|
|
|
23221e |
|
|
|
23221e |
Signed-off-by: Patrick Talbert <ptalbert@redhat.com>
|
|
|
23221e |
|
|
|
23221e |
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
|
|
|
23221e |
---
|
|
|
23221e |
net/unix/af_unix.c | 51 ++++++++++++++++++++++++++++++++++++++++++++--
|
|
|
23221e |
1 file changed, 49 insertions(+), 2 deletions(-)
|
|
|
23221e |
|
|
|
23221e |
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
|
|
|
23221e |
index 247e3138d1ef..d9c968caaf20 100644
|
|
|
23221e |
--- a/net/unix/af_unix.c
|
|
|
23221e |
+++ b/net/unix/af_unix.c
|
|
|
23221e |
@@ -1498,6 +1498,53 @@ static int unix_getname(struct socket *sock, struct sockaddr *uaddr, int peer)
|
|
|
23221e |
return err;
|
|
|
23221e |
}
|
|
|
23221e |
|
|
|
23221e |
+static void unix_peek_fds(struct scm_cookie *scm, struct sk_buff *skb)
|
|
|
23221e |
+{
|
|
|
23221e |
+ scm->fp = scm_fp_dup(UNIXCB(skb).fp);
|
|
|
23221e |
+
|
|
|
23221e |
+ /*
|
|
|
23221e |
+ * Garbage collection of unix sockets starts by selecting a set of
|
|
|
23221e |
+ * candidate sockets which have reference only from being in flight
|
|
|
23221e |
+ * (total_refs == inflight_refs). This condition is checked once during
|
|
|
23221e |
+ * the candidate collection phase, and candidates are marked as such, so
|
|
|
23221e |
+ * that non-candidates can later be ignored. While inflight_refs is
|
|
|
23221e |
+ * protected by unix_gc_lock, total_refs (file count) is not, hence this
|
|
|
23221e |
+ * is an instantaneous decision.
|
|
|
23221e |
+ *
|
|
|
23221e |
+ * Once a candidate, however, the socket must not be reinstalled into a
|
|
|
23221e |
+ * file descriptor while the garbage collection is in progress.
|
|
|
23221e |
+ *
|
|
|
23221e |
+ * If the above conditions are met, then the directed graph of
|
|
|
23221e |
+ * candidates (*) does not change while unix_gc_lock is held.
|
|
|
23221e |
+ *
|
|
|
23221e |
+ * Any operations that changes the file count through file descriptors
|
|
|
23221e |
+ * (dup, close, sendmsg) does not change the graph since candidates are
|
|
|
23221e |
+ * not installed in fds.
|
|
|
23221e |
+ *
|
|
|
23221e |
+ * Dequeing a candidate via recvmsg would install it into an fd, but
|
|
|
23221e |
+ * that takes unix_gc_lock to decrement the inflight count, so it's
|
|
|
23221e |
+ * serialized with garbage collection.
|
|
|
23221e |
+ *
|
|
|
23221e |
+ * MSG_PEEK is special in that it does not change the inflight count,
|
|
|
23221e |
+ * yet does install the socket into an fd. The following lock/unlock
|
|
|
23221e |
+ * pair is to ensure serialization with garbage collection. It must be
|
|
|
23221e |
+ * done between incrementing the file count and installing the file into
|
|
|
23221e |
+ * an fd.
|
|
|
23221e |
+ *
|
|
|
23221e |
+ * If garbage collection starts after the barrier provided by the
|
|
|
23221e |
+ * lock/unlock, then it will see the elevated refcount and not mark this
|
|
|
23221e |
+ * as a candidate. If a garbage collection is already in progress
|
|
|
23221e |
+ * before the file count was incremented, then the lock/unlock pair will
|
|
|
23221e |
+ * ensure that garbage collection is finished before progressing to
|
|
|
23221e |
+ * installing the fd.
|
|
|
23221e |
+ *
|
|
|
23221e |
+ * (*) A -> B where B is on the queue of A or B is on the queue of C
|
|
|
23221e |
+ * which is on the queue of listening socket A.
|
|
|
23221e |
+ */
|
|
|
23221e |
+ spin_lock(&unix_gc_lock);
|
|
|
23221e |
+ spin_unlock(&unix_gc_lock);
|
|
|
23221e |
+}
|
|
|
23221e |
+
|
|
|
23221e |
static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool send_fds)
|
|
|
23221e |
{
|
|
|
23221e |
int err = 0;
|
|
|
23221e |
@@ -2124,7 +2171,7 @@ static int unix_dgram_recvmsg(struct socket *sock, struct msghdr *msg,
|
|
|
23221e |
sk_peek_offset_fwd(sk, size);
|
|
|
23221e |
|
|
|
23221e |
if (UNIXCB(skb).fp)
|
|
|
23221e |
- scm.fp = scm_fp_dup(UNIXCB(skb).fp);
|
|
|
23221e |
+ unix_peek_fds(&scm, skb);
|
|
|
23221e |
}
|
|
|
23221e |
err = (flags & MSG_TRUNC) ? skb->len - skip : size;
|
|
|
23221e |
|
|
|
23221e |
@@ -2365,7 +2412,7 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
|
|
|
23221e |
/* It is questionable, see note in unix_dgram_recvmsg.
|
|
|
23221e |
*/
|
|
|
23221e |
if (UNIXCB(skb).fp)
|
|
|
23221e |
- scm.fp = scm_fp_dup(UNIXCB(skb).fp);
|
|
|
23221e |
+ unix_peek_fds(&scm, skb);
|
|
|
23221e |
|
|
|
23221e |
sk_peek_offset_fwd(sk, chunk);
|
|
|
23221e |
|
|
|
23221e |
--
|
|
|
23221e |
2.34.1
|
|
|
23221e |
|
|
|
23221e |
|