Blame SOURCES/0001-libsepol-cil-Fix-out-of-bound-read-of-file-context-p.patch

1ae9de
From 2b2f42f9311ede75c3fe61d356094999e8e161b9 Mon Sep 17 00:00:00 2001
1ae9de
From: James Carter <jwcart2@gmail.com>
1ae9de
Date: Thu, 8 Apr 2021 13:24:29 -0400
1ae9de
Subject: [PATCH] libsepol/cil: Fix out-of-bound read of file context pattern
1ae9de
 ending with "\"
1ae9de
1ae9de
Based on patch by Nicolas Iooss, who writes:
1ae9de
  OSS-Fuzz found a Heap-buffer-overflow in the CIL compiler when trying
1ae9de
  to compile the following policy:
1ae9de
1ae9de
    (sid SID)
1ae9de
    (sidorder(SID))
1ae9de
    (filecon "\" any ())
1ae9de
    (filecon "" any ())
1ae9de
1ae9de
  When cil_post_fc_fill_data() processes "\", it goes beyond the NUL
1ae9de
  terminator of the string. Fix this by returning when '\0' is read
1ae9de
  after a backslash.
1ae9de
1ae9de
To be consistent with the function compute_diffdata() in
1ae9de
refpolicy/support/fc_sort.py, also increment str_len in this case.
1ae9de
1ae9de
Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28484
1ae9de
Reported-by: Nicolas Iooss <nicolas.iooss@m4x.org>
1ae9de
Signed-off-by: James Carter <jwcart2@gmail.com>
1ae9de
---
1ae9de
 libsepol/cil/src/cil_post.c | 7 +++++++
1ae9de
 1 file changed, 7 insertions(+)
1ae9de
1ae9de
diff --git a/libsepol/cil/src/cil_post.c b/libsepol/cil/src/cil_post.c
1ae9de
index 0b09cecc..bdeaa7c6 100644
1ae9de
--- a/libsepol/cil/src/cil_post.c
1ae9de
+++ b/libsepol/cil/src/cil_post.c
1ae9de
@@ -179,6 +179,13 @@ void cil_post_fc_fill_data(struct fc_data *fc, char *path)
1ae9de
 			break;
1ae9de
 		case '\\':
1ae9de
 			c++;
1ae9de
+			if (path[c] == '\0') {
1ae9de
+				if (!fc->meta) {
1ae9de
+					fc->stem_len++;
1ae9de
+				}
1ae9de
+				fc->str_len++;
1ae9de
+				return;
1ae9de
+			}
1ae9de
 			/* FALLTHRU */
1ae9de
 		default:
1ae9de
 			if (!fc->meta) {
1ae9de
-- 
1ae9de
2.30.2
1ae9de