Blame SOURCES/0052-handle-large-service-tickets.patch

3247ef
From b6efe6b119b0c11314a324e8a2cf96fb74a9c983 Mon Sep 17 00:00:00 2001
3247ef
From: Sam Morris <sam@robots.org.uk>
3247ef
Date: Tue, 6 Apr 2021 18:42:19 +0100
3247ef
Subject: [PATCH 1/6] responder/common/responder_packet: handle large service
3247ef
 tickets
3247ef
3247ef
Resolves: https://github.com/SSSD/sssd/issues/5568
3247ef
3247ef
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
3247ef
---
3247ef
 src/responder/common/responder_packet.c | 11 +++++++++++
3247ef
 src/responder/common/responder_packet.h |  1 +
3247ef
 2 files changed, 12 insertions(+)
3247ef
3247ef
diff --git a/src/responder/common/responder_packet.c b/src/responder/common/responder_packet.c
3247ef
index f56d92276..d091332b0 100644
3247ef
--- a/src/responder/common/responder_packet.c
3247ef
+++ b/src/responder/common/responder_packet.c
3247ef
@@ -229,6 +229,17 @@ int sss_packet_recv(struct sss_packet *packet, int fd)
3247ef
             if (ret != EOK) {
3247ef
                 return ret;
3247ef
             }
3247ef
+	/* Kerberos tickets can get pretty big; since Windows Server 2012, the
3247ef
+	 * limit is 48 KiB!
3247ef
+	 */
3247ef
+	} else if ((sss_packet_get_cmd(packet) == SSS_GSSAPI_SEC_CTX)
3247ef
+                && packet->memsize < SSS_GSSAPI_PACKET_MAX_RECV_SIZE
3247ef
+                && new_len < SSS_GSSAPI_PACKET_MAX_RECV_SIZE) {
3247ef
+            sss_packet_set_len(packet, 0);
3247ef
+            ret = sss_packet_grow(packet, new_len);
3247ef
+            if (ret != EOK) {
3247ef
+                return ret;
3247ef
+            }
3247ef
         } else {
3247ef
             return EINVAL;
3247ef
         }
3247ef
diff --git a/src/responder/common/responder_packet.h b/src/responder/common/responder_packet.h
3247ef
index 509a22a9a..70bf1e8d3 100644
3247ef
--- a/src/responder/common/responder_packet.h
3247ef
+++ b/src/responder/common/responder_packet.h
3247ef
@@ -26,6 +26,7 @@
3247ef
 
3247ef
 #define SSS_PACKET_MAX_RECV_SIZE 1024
3247ef
 #define SSS_CERT_PACKET_MAX_RECV_SIZE ( 10 * SSS_PACKET_MAX_RECV_SIZE )
3247ef
+#define SSS_GSSAPI_PACKET_MAX_RECV_SIZE ( SSS_PACKET_MAX_RECV_SIZE + 48 * 1024 )
3247ef
 
3247ef
 struct sss_packet;
3247ef
 
3247ef
-- 
3247ef
2.26.3
3247ef
3247ef
3247ef
From c6a76283580c25ff78b36b8b23efdabbdb3a2cc1 Mon Sep 17 00:00:00 2001
3247ef
From: Sam Morris <sam@robots.org.uk>
3247ef
Date: Wed, 7 Apr 2021 14:21:34 +0100
3247ef
Subject: [PATCH 2/6] responder/common/responder_packet: reduce duplication of
3247ef
 code that handles larger-than-normal packets
3247ef
3247ef
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
3247ef
---
3247ef
 src/responder/common/responder_packet.c | 40 +++++++++++++------------
3247ef
 1 file changed, 21 insertions(+), 19 deletions(-)
3247ef
3247ef
diff --git a/src/responder/common/responder_packet.c b/src/responder/common/responder_packet.c
3247ef
index d091332b0..523c9ddd4 100644
3247ef
--- a/src/responder/common/responder_packet.c
3247ef
+++ b/src/responder/common/responder_packet.c
3247ef
@@ -216,25 +216,27 @@ int sss_packet_recv(struct sss_packet *packet, int fd)
3247ef
 
3247ef
     new_len = sss_packet_get_len(packet);
3247ef
     if (new_len > packet->memsize) {
3247ef
-        /* Allow certificate based requests to use larger buffer but not
3247ef
-         * larger than SSS_CERT_PACKET_MAX_RECV_SIZE. Due to the way
3247ef
-         * sss_packet_grow() works the packet len must be set to '0' first and
3247ef
-         * then grow to the expected size. */
3247ef
-        if ((sss_packet_get_cmd(packet) == SSS_NSS_GETNAMEBYCERT
3247ef
-                    || sss_packet_get_cmd(packet) == SSS_NSS_GETLISTBYCERT)
3247ef
-                && packet->memsize < SSS_CERT_PACKET_MAX_RECV_SIZE
3247ef
-                && new_len < SSS_CERT_PACKET_MAX_RECV_SIZE) {
3247ef
-            sss_packet_set_len(packet, 0);
3247ef
-            ret = sss_packet_grow(packet, new_len);
3247ef
-            if (ret != EOK) {
3247ef
-                return ret;
3247ef
-            }
3247ef
-	/* Kerberos tickets can get pretty big; since Windows Server 2012, the
3247ef
-	 * limit is 48 KiB!
3247ef
-	 */
3247ef
-	} else if ((sss_packet_get_cmd(packet) == SSS_GSSAPI_SEC_CTX)
3247ef
-                && packet->memsize < SSS_GSSAPI_PACKET_MAX_RECV_SIZE
3247ef
-                && new_len < SSS_GSSAPI_PACKET_MAX_RECV_SIZE) {
3247ef
+        enum sss_cli_command cmd = sss_packet_get_cmd(packet);
3247ef
+        size_t max_recv_size;
3247ef
+
3247ef
+        /* Allow certain packet types to use a larger buffer. */
3247ef
+        switch (cmd) {
3247ef
+        case SSS_NSS_GETNAMEBYCERT:
3247ef
+        case SSS_NSS_GETLISTBYCERT:
3247ef
+            max_recv_size = SSS_CERT_PACKET_MAX_RECV_SIZE;
3247ef
+            break;
3247ef
+
3247ef
+        case SSS_GSSAPI_SEC_CTX:
3247ef
+            max_recv_size = SSS_GSSAPI_PACKET_MAX_RECV_SIZE;
3247ef
+            break;
3247ef
+
3247ef
+        default:
3247ef
+            max_recv_size = 0;
3247ef
+        }
3247ef
+
3247ef
+        /* Due to the way sss_packet_grow() works, the packet len must be set
3247ef
+         * to 0 first, and then grown to the expected size. */
3247ef
+        if (max_recv_size && packet->memsize < max_recv_size && new_len < max_recv_size) {
3247ef
             sss_packet_set_len(packet, 0);
3247ef
             ret = sss_packet_grow(packet, new_len);
3247ef
             if (ret != EOK) {
3247ef
-- 
3247ef
2.26.3
3247ef
3247ef
3247ef
From 63f318f73c933dc2cb08cad2f911a52d2281c45b Mon Sep 17 00:00:00 2001
3247ef
From: Sam Morris <sam@robots.org.uk>
3247ef
Date: Wed, 7 Apr 2021 14:22:25 +0100
3247ef
Subject: [PATCH 3/6] responder/common/responder_packet: add debug logging to
3247ef
 assist with errors caused by overlarge packets
3247ef
3247ef
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
3247ef
---
3247ef
 src/responder/common/responder_packet.c | 3 +++
3247ef
 1 file changed, 3 insertions(+)
3247ef
3247ef
diff --git a/src/responder/common/responder_packet.c b/src/responder/common/responder_packet.c
3247ef
index 523c9ddd4..01a4e640e 100644
3247ef
--- a/src/responder/common/responder_packet.c
3247ef
+++ b/src/responder/common/responder_packet.c
3247ef
@@ -243,6 +243,9 @@ int sss_packet_recv(struct sss_packet *packet, int fd)
3247ef
                 return ret;
3247ef
             }
3247ef
         } else {
3247ef
+            DEBUG(SSSDBG_OP_FAILURE,
3247ef
+                "Refusing to read overlarge packet from fd %d (length %zu bytes, cmd %#04x)",
3247ef
+                    fd, new_len, cmd);
3247ef
             return EINVAL;
3247ef
         }
3247ef
     }
3247ef
-- 
3247ef
2.26.3
3247ef
3247ef
3247ef
From 37d331774385b2b871ba76fcdef6ceafd776efce Mon Sep 17 00:00:00 2001
3247ef
From: Sam Morris <sam@robots.org.uk>
3247ef
Date: Wed, 7 Apr 2021 14:23:03 +0100
3247ef
Subject: [PATCH 4/6] responder/common/responder_packet: further increase
3247ef
 packet size for SSS_GSSAPI_SEC_CTX
3247ef
3247ef
Tokens can be 48 KiB in Windows Server 2012. Limiting to 128 KiB
3247ef
provides extra overhead should that increase in the future.
3247ef
3247ef
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
3247ef
---
3247ef
 src/responder/common/responder_packet.h | 2 +-
3247ef
 1 file changed, 1 insertion(+), 1 deletion(-)
3247ef
3247ef
diff --git a/src/responder/common/responder_packet.h b/src/responder/common/responder_packet.h
3247ef
index 70bf1e8d3..fd991969b 100644
3247ef
--- a/src/responder/common/responder_packet.h
3247ef
+++ b/src/responder/common/responder_packet.h
3247ef
@@ -26,7 +26,7 @@
3247ef
 
3247ef
 #define SSS_PACKET_MAX_RECV_SIZE 1024
3247ef
 #define SSS_CERT_PACKET_MAX_RECV_SIZE ( 10 * SSS_PACKET_MAX_RECV_SIZE )
3247ef
-#define SSS_GSSAPI_PACKET_MAX_RECV_SIZE ( SSS_PACKET_MAX_RECV_SIZE + 48 * 1024 )
3247ef
+#define SSS_GSSAPI_PACKET_MAX_RECV_SIZE ( 128 * 1024 )
3247ef
 
3247ef
 struct sss_packet;
3247ef
 
3247ef
-- 
3247ef
2.26.3
3247ef
3247ef
3247ef
From 5c9fa75bd0ffa02e31cbbf19ee68134ed384229a Mon Sep 17 00:00:00 2001
3247ef
From: Sam Morris <sam@robots.org.uk>
3247ef
Date: Wed, 7 Apr 2021 19:59:45 +0100
3247ef
Subject: [PATCH 5/6] responder/common/responder_packet: remove some
3247ef
 unnecessary checks before growing packet
3247ef
3247ef
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
3247ef
---
3247ef
 src/responder/common/responder_packet.c | 2 +-
3247ef
 1 file changed, 1 insertion(+), 1 deletion(-)
3247ef
3247ef
diff --git a/src/responder/common/responder_packet.c b/src/responder/common/responder_packet.c
3247ef
index 01a4e640e..c4b38f71b 100644
3247ef
--- a/src/responder/common/responder_packet.c
3247ef
+++ b/src/responder/common/responder_packet.c
3247ef
@@ -236,7 +236,7 @@ int sss_packet_recv(struct sss_packet *packet, int fd)
3247ef
 
3247ef
         /* Due to the way sss_packet_grow() works, the packet len must be set
3247ef
          * to 0 first, and then grown to the expected size. */
3247ef
-        if (max_recv_size && packet->memsize < max_recv_size && new_len < max_recv_size) {
3247ef
+        if (new_len < max_recv_size) {
3247ef
             sss_packet_set_len(packet, 0);
3247ef
             ret = sss_packet_grow(packet, new_len);
3247ef
             if (ret != EOK) {
3247ef
-- 
3247ef
2.26.3
3247ef
3247ef
3247ef
From b87619f9a917d6ed9ecdb5360c4bf242dce8e372 Mon Sep 17 00:00:00 2001
3247ef
From: Sam Morris <sam@robots.org.uk>
3247ef
Date: Thu, 8 Apr 2021 19:09:33 +0100
3247ef
Subject: [PATCH 6/6] responder/common/responder_packet: allow packets of max
3247ef
 size
3247ef
3247ef
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
3247ef
---
3247ef
 src/responder/common/responder_packet.c | 2 +-
3247ef
 1 file changed, 1 insertion(+), 1 deletion(-)
3247ef
3247ef
diff --git a/src/responder/common/responder_packet.c b/src/responder/common/responder_packet.c
3247ef
index c4b38f71b..f2223c665 100644
3247ef
--- a/src/responder/common/responder_packet.c
3247ef
+++ b/src/responder/common/responder_packet.c
3247ef
@@ -236,7 +236,7 @@ int sss_packet_recv(struct sss_packet *packet, int fd)
3247ef
 
3247ef
         /* Due to the way sss_packet_grow() works, the packet len must be set
3247ef
          * to 0 first, and then grown to the expected size. */
3247ef
-        if (new_len < max_recv_size) {
3247ef
+        if (new_len <= max_recv_size) {
3247ef
             sss_packet_set_len(packet, 0);
3247ef
             ret = sss_packet_grow(packet, new_len);
3247ef
             if (ret != EOK) {
3247ef
-- 
3247ef
2.26.3
3247ef