mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-09-22 09:34:56 +02:00
audit: fix potential integer overflow in audit_log_n_hex()
[ Upstream commit65dfde57d1] The function calculates new_len as len << 1 for hex encoding. This has two overflow risks: the shift itself can overflow when len is large, and the result can be truncated when assigned to new_len (declared as int) from the size_t calculation. Fix by using check_shl_overflow() to catch shift overflow and changing new_len and loop counter i to size_t to prevent truncation. Cc: stable@vger.kernel.org Fixes:168b717395("AUDIT: Clean up logging of untrusted strings") Reviewed-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Ricardo Robaina <rrobaina@redhat.com> [PM: remove vertical whitspace noise] Signed-off-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
fc7e17d2f7
commit
1526f3c988
+9
-2
@@ -59,6 +59,7 @@
|
||||
#include <net/netns/generic.h>
|
||||
#include <net/ip.h>
|
||||
#include <net/ipv6.h>
|
||||
#include <linux/overflow.h>
|
||||
|
||||
#include "audit.h"
|
||||
|
||||
@@ -2034,7 +2035,8 @@ void audit_log_format(struct audit_buffer *ab, const char *fmt, ...)
|
||||
void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
|
||||
size_t len)
|
||||
{
|
||||
int i, avail, new_len;
|
||||
int avail;
|
||||
size_t i, new_len;
|
||||
unsigned char *ptr;
|
||||
struct sk_buff *skb;
|
||||
|
||||
@@ -2044,7 +2046,12 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
|
||||
BUG_ON(!ab->skb);
|
||||
skb = ab->skb;
|
||||
avail = skb_tailroom(skb);
|
||||
new_len = len<<1;
|
||||
|
||||
if (check_shl_overflow(len, 1, &new_len)) {
|
||||
audit_log_format(ab, "?");
|
||||
return;
|
||||
}
|
||||
|
||||
if (new_len >= avail) {
|
||||
/* Round the buffer request up to the next multiple */
|
||||
new_len = AUDIT_BUFSIZ*(((new_len-avail)/AUDIT_BUFSIZ) + 1);
|
||||
|
||||
Reference in New Issue
Block a user