From 42523bae91eb14f8ffb604db76da60892abbdc1c Mon Sep 17 00:00:00 2001 From: John Johansen Date: Thu, 18 Jul 2024 06:15:05 -0700 Subject: [PATCH] Revert "parser: fix potential padding bug." This reverts commit 78ae95608753b42956f2445a4965b0577fbb76de. Commit 78ae95608753b42956f2445a4965b0577fbb76de causes policy to not to conform to protocol as determined by the kernel. Technically the reverted patch is correct and the kernel is wrong but we can not change 15 years of history. The reason it breaks the policy in the kernel is because the kernel does not use the name field, and does not expect it. It just expects the size with a single trailing 0. This doesn't break because this section is all padded to 64 bytes so writing the extra 0 doesn't hurt as it is effectively just manually adding to the padding. Signed-off-by: John Johansen --- parser/libapparmor_re/chfa.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parser/libapparmor_re/chfa.cc b/parser/libapparmor_re/chfa.cc index 25edf43e5..658218958 100644 --- a/parser/libapparmor_re/chfa.cc +++ b/parser/libapparmor_re/chfa.cc @@ -419,7 +419,7 @@ void CHFA::flex_table(ostream &os, const char *name) /* Write the actual flex parser table. */ /* TODO: add max_oob */ - size_t hsize = pad64(sizeof(th) + sizeof(th_version) + 1 + strlen(name) + 1); + size_t hsize = pad64(sizeof(th) + sizeof(th_version) + strlen(name) + 1); th.th_magic = htonl(YYTH_REGEX_MAGIC); th.th_flags = htons(chfaflags); th.th_hsize = htonl(hsize); @@ -433,7 +433,7 @@ void CHFA::flex_table(ostream &os, const char *name) flex_table_size(check_vec.begin(), check_vec.end())); os.write((char *)&th, sizeof(th)); os << th_version << (char)0 << name << (char)0; - os << fill64(sizeof(th) + 1 + sizeof(th_version) + strlen(name) + 1); + os << fill64(sizeof(th) + sizeof(th_version) + strlen(name) + 1); write_flex_table(os, YYTD_ID_ACCEPT, accept.begin(), accept.end()); write_flex_table(os, YYTD_ID_ACCEPT2, accept2.begin(), accept2.end());