Skip to contentSkip to conversation

auditsc: Implement a workaround for a GCC bug triggered by task comm changes

PATCH In review Yafang Shao 2 participants 2 messages Dec 5, 2024 Audit

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 auditsc: Implement a workaround for a GCC bug triggered by task comm changes

From: Yafang shao <[email protected]>

A build failure has been reported with the following details:

In file included from include/linux/string.h:390,
from include/linux/bitmap.h:13, from include/linux/cpumask.h:12, from include/linux/smp.h:13, from include/linux/lockdep.h:14, from include/linux/spinlock.h:63, from include/linux/wait.h:9, from include/linux/wait_bit.h:8, from include/linux/fs.h:6, from kernel/auditsc.c:37:
In function 'sized_strscpy',

       inlined from '__audit_ptrace' at kernel/auditsc.c:2732:2:
Quoted 1 line
Quoted 1 line

include/linux/fortify-string.h:293:17: error: call to '__write_overflow' declared with attribute error: detected write beyond size of object (1st parameter)

     293 |                 __write_overflow();
         |                 ^~~~~~~~~~~~~~~~~~

In function 'sized_strscpy',
inlined from 'audit_signal_info_syscall' at kernel/auditsc.c:2759:3:

Quoted 1 line
Quoted 1 line

include/linux/fortify-string.h:293:17: error: call to '__write_overflow' declared with attribute error: detected write beyond size of object (1st parameter)

     293 |                 __write_overflow();
         |                 ^~~~~~~~~~~~~~~~~~

The issue appears to be a GCC bug, though the root cause remains unclear at this time. For now, let's implement a workaround.

A bug report has also been filed with GCC [0].

---
 kernel/auditsc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

v1->2: Add the link of the GCC bug report

kernel/auditsc.c +2 -2
index 279ba5c420a4..561d96affe9f 100644
@@ -2728,8 +2728,8 @@ void __audit_ptrace(struct task_struct *t)
 	context->target_auid = audit_get_loginuid(t);
 	context->target_uid = task_uid(t);
 	context->target_sessionid = audit_get_sessionid(t);
-	security_task_getlsmprop_obj(t, &context->target_ref);
 	strscpy(context->target_comm, t->comm);
+	security_task_getlsmprop_obj(t, &context->target_ref);
 }
 
 /**
@@ -2755,8 +2755,8 @@ int audit_signal_info_syscall(struct task_struct *t)
 		ctx->target_auid = audit_get_loginuid(t);
 		ctx->target_uid = t_uid;
 		ctx->target_sessionid = audit_get_sessionid(t);
-		security_task_getlsmprop_obj(t, &ctx->target_ref);
 		strscpy(ctx->target_comm, t->comm);
+		security_task_getlsmprop_obj(t, &ctx->target_ref);
 		return 0;
 	}
 
Signature · 1 line
2.43.5
maintainer
#1 lore raw
Quoted 42 lines · On Dec 4, 2024 Yafang Shao <[email protected]> wrote:

A build failure has been reported with the following details:

In file included from include/linux/string.h:390,
from include/linux/bitmap.h:13, from include/linux/cpumask.h:12, from include/linux/smp.h:13, from include/linux/lockdep.h:14, from include/linux/spinlock.h:63, from include/linux/wait.h:9, from include/linux/wait_bit.h:8, from include/linux/fs.h:6, from kernel/auditsc.c:37:
In function 'sized_strscpy',

       inlined from '__audit_ptrace' at kernel/auditsc.c:2732:2:
Quoted 1 line
Quoted 1 line

include/linux/fortify-string.h:293:17: error: call to '__write_overflow' declared with attribute error: detected write beyond size of object (1st parameter)

     293 |                 __write_overflow();
         |                 ^~~~~~~~~~~~~~~~~~

In function 'sized_strscpy',
inlined from 'audit_signal_info_syscall' at kernel/auditsc.c:2759:3:

Quoted 1 line
Quoted 1 line

include/linux/fortify-string.h:293:17: error: call to '__write_overflow' declared with attribute error: detected write beyond size of object (1st parameter)

     293 |                 __write_overflow();
         |                 ^~~~~~~~~~~~~~~~~~

The issue appears to be a GCC bug, though the root cause remains unclear at this time. For now, let's implement a workaround.

A bug report has also been filed with GCC [0].

Quoted 5 lines
---
 kernel/auditsc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

v1->2: Add the link of the GCC bug report

Thanks, it looks like the GCC devs have been able to reproduce the problem, hopefully we'll have a proper fix soon. Regardless, we need to resolve this in the kernel *now* so I'm going to merge this into the audit/stable-6.12 branch and I'll send it up to Linus after it clears testing.

Quoted 26 lines
kernel/auditsc.c +2 -2
index 279ba5c420a4..561d96affe9f 100644
@@ -2728,8 +2728,8 @@ void __audit_ptrace(struct task_struct *t)
 	context->target_auid = audit_get_loginuid(t);
 	context->target_uid = task_uid(t);
 	context->target_sessionid = audit_get_sessionid(t);
-	security_task_getlsmprop_obj(t, &context->target_ref);
 	strscpy(context->target_comm, t->comm);
+	security_task_getlsmprop_obj(t, &context->target_ref);
 }
 
 /**
@@ -2755,8 +2755,8 @@ int audit_signal_info_syscall(struct task_struct *t)
 		ctx->target_auid = audit_get_loginuid(t);
 		ctx->target_uid = t_uid;
 		ctx->target_sessionid = audit_get_sessionid(t);
-		security_task_getlsmprop_obj(t, &ctx->target_ref);
 		strscpy(ctx->target_comm, t->comm);
+		security_task_getlsmprop_obj(t, &ctx->target_ref);
 		return 0;
 	}
 
Signature · 1 line
2.43.5

--
paul-moore.com