audit: drop BUG_ON() from audit_log_XXX()
Paul Moore
maintainerRFC PATCH 1/1 audit: drop BUG_ON() from audit_log_XXX()
We can easily drop the BUG_ON()s from the audit_log_XXX() helpers and simply return to the caller as we do if we are passed a NULL audit_buffer.
--- kernel/audit.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
kernel/audit.c +3 -6
@@ -2016,10 +2016,9 @@ void audit_log_vformat(struct audit_buffer *ab, const char *fmt, va_list args)struct sk_buff *skb;va_list args2; -if (!ab) +if (!ab || !ab->skb)return ; -BUG_ON (!ab->skb); skb = ab->skb; avail =skb_tailroom (skb);if (avail ==0 ) {
@@ -2084,10 +2083,9 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,unsigned char *ptr;struct sk_buff *skb; -if (!ab) +if (!ab || !ab->skb)return ; -BUG_ON (!ab->skb); skb = ab->skb; avail =skb_tailroom (skb); new_len = len<<1 ;
@@ -2117,10 +2115,9 @@ void audit_log_n_string(struct audit_buffer *ab, const char *string,unsigned char *ptr;struct sk_buff *skb; -if (!ab) +if (!ab || !ab->skb)return ; -BUG_ON (!ab->skb); skb = ab->skb; avail =skb_tailroom (skb); new_len = slen +3 ;/* enclosing quotes + null terminator */
Signature · 1 line
2.55.0
Quoted 51 lines · Paul Moore
We can easily drop the BUG_ON()s from the
audit_log_XXX()helpers and simply return to the caller as we do if we are passed a NULLaudit_buffer.Signed-off-by Paul Moore <[email protected]>--- kernel/audit.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)kernel/audit.c +3
-7@@ -2016,10 +2016,9 @@ void audit_log_vformat(struct audit_buffer *ab, const char *fmt, va_list args)struct sk_buff *skb;va_list args2; -if (!ab) +if (!ab || !ab->skb)return ; -BUG_ON (!ab->skb); skb = ab->skb; avail =skb_tailroom (skb);if (avail ==0 ) {@@ -2084,10 +2083,9 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,unsigned char *ptr;struct sk_buff *skb; -if (!ab) +if (!ab || !ab->skb)return ; -BUG_ON (!ab->skb); skb = ab->skb; avail =skb_tailroom (skb); new_len = len<<1 ;@@ -2117,10 +2115,9 @@ void audit_log_n_string(struct audit_buffer *ab, const char *string,unsigned char *ptr;struct sk_buff *skb; -if (!ab) +if (!ab || !ab->skb)return ; -BUG_ON (!ab->skb); skb = ab->skb; avail =skb_tailroom (skb); new_len = slen +3 ;/* enclosing quotes + null terminator */ --
Quoted 3 lines
2.55.0
Hi Paul,
It looks good to me. I agree that it was not worth panicking the kernel in these cases.
I was taking a look at other BUG_ON instances and noticed a couple that might benefit from similar treatment:
1. In audit_add_to_parent() at kernel/audit_watch.c:375:
BUG_ON(!mutex_is_locked(&audit_filter_mutex));
Couldn't we use lockdep_assert_held() instead?
2. In __audit_log_bprm_fcaps() at kernel/auditsc.c:2715:
BUG_ON(axp->pid_count >= AUDIT_AUX_PIDS);
This could gracefully return an error instead of panicking.
I can send patches for these if you think they're worthwhile.
-Ricardo
Paul Moore
maintainerQuoted 10 lines · Ricardo Robaina
Quoted 9 lines · Paul Moore
We can easily drop the BUG_ON()s from the
audit_log_XXX()helpers and simply return to the caller as we do if we are passed a NULLaudit_buffer.Signed-off-by Paul Moore <[email protected]>--- kernel/audit.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
...
Quoted 5 lines
Hi Paul,
It looks good to me. I agree that it was not worth panicking the kernel in these cases.
Reviewed-by Ricardo Robaina <[email protected]>
Thanks for taking a look. As an FYI, I'm dropping this patch as I'm folding it into a larger patchset that I'll post as soon as I have a chance to test it. While looking at the overflow checks in the logging functions I was "inspired" to fix a number of related problems this afternoon and this BUG_ON fix fit well with the new patchset.
Quoted 7 lines
I was taking a look at other
BUG_ONinstances and noticed a couple that might benefit from similar treatment:1. In
audit_add_to_parent()atkernel/audit_watch.c:375:
BUG_ON(!mutex_is_locked(&audit_filter_mutex));Couldn't we use
lockdep_assert_held()instead?
I believe so. Nice catch :)
Quoted 4 lines
2. In
__audit_log_bprm_fcaps()atkernel/auditsc.c:2715:
BUG_ON(axp->pid_count >= AUDIT_AUX_PIDS);This could gracefully return an error instead of panicking.
I'm assuming you meant audit_signal_info_syscall()? If so, yes, this would be another good improvement.
Quoted 1 line
I can send patches for these if you think they're worthwhile.
That would be great, thanks!
Signature · 1 line
paul-moore.com
Quoted 37 lines · Paul Moore
Quoted 10 lines · Ricardo Robaina
Quoted 9 lines · Paul Moore
We can easily drop the BUG_ON()s from the
audit_log_XXX()helpers and simply return to the caller as we do if we are passed a NULLaudit_buffer.Signed-off-by Paul Moore <[email protected]>--- kernel/audit.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)...
Quoted 5 lines
Hi Paul,
It looks good to me. I agree that it was not worth panicking the kernel in these cases.
Reviewed-by Ricardo Robaina <[email protected]>Thanks for taking a look. As an FYI, I'm dropping this patch as I'm folding it into a larger patchset that I'll post as soon as I have a chance to test it. While looking at the overflow checks in the logging functions I was "inspired" to fix a number of related problems this afternoon and this
BUG_ONfix fit well with the new patchset.Quoted 7 lines
I was taking a look at other
BUG_ONinstances and noticed a couple that might benefit from similar treatment:1. In
audit_add_to_parent()atkernel/audit_watch.c:375:
BUG_ON(!mutex_is_locked(&audit_filter_mutex));Couldn't we use
lockdep_assert_held()instead?I believe so. Nice catch :)
Quoted 7 lines
Quoted 4 lines
2. In
__audit_log_bprm_fcaps()atkernel/auditsc.c:2715:
BUG_ON(axp->pid_count >= AUDIT_AUX_PIDS);This could gracefully return an error instead of panicking.
I'm assuming you meant
audit_signal_info_syscall()? If so, yes, this would be another good improvement.
You're right, I meant audit_signal_info_syscall(). I'll prepare a patch series addressing both cases, then. Thanks, Paul.
Quoted 8 lines
Quoted 2 lines
I can send patches for these if you think they're worthwhile.
That would be great, thanks!
--
paul-moore.com
-Ricardo
Paul Moore
maintainerQuoted 40 lines · Ricardo Robaina
Quoted 39 lines · Paul Moore
Quoted 10 lines · Ricardo Robaina
Quoted 9 lines · Paul Moore
We can easily drop the BUG_ON()s from the
audit_log_XXX()helpers and simply return to the caller as we do if we are passed a NULLaudit_buffer.Signed-off-by Paul Moore <[email protected]>--- kernel/audit.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)...
Quoted 5 lines
Hi Paul,
It looks good to me. I agree that it was not worth panicking the kernel in these cases.
Reviewed-by Ricardo Robaina <[email protected]>Thanks for taking a look. As an FYI, I'm dropping this patch as I'm folding it into a larger patchset that I'll post as soon as I have a chance to test it. While looking at the overflow checks in the logging functions I was "inspired" to fix a number of related problems this afternoon and this
BUG_ONfix fit well with the new patchset.Quoted 7 lines
I was taking a look at other
BUG_ONinstances and noticed a couple that might benefit from similar treatment:1. In
audit_add_to_parent()atkernel/audit_watch.c:375:
BUG_ON(!mutex_is_locked(&audit_filter_mutex));Couldn't we use
lockdep_assert_held()instead?I believe so. Nice catch :)
Quoted 3 lines
2. In
__audit_log_bprm_fcaps()atkernel/auditsc.c:2715:BUG_ON(axp->pid_count >= AUDIT_AUX_PIDS);
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This could gracefully return an error instead of panicking.
I'm assuming you meant
audit_signal_info_syscall()? If so, yes, this would be another good improvement.You're right, I meant
audit_signal_info_syscall(). I'll prepare a patch series addressing both cases, then. Thanks, Paul.
Great, thanks!
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
I can send patches for these if you think they're worthwhile.
That would be great, thanks!
Signature · 1 line
paul-moore.com