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

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