AX.25: Fix out-of-bounds read in ax25_connect()
Subsystems (2)
PATCH 1/1 AX.25: Fix out-of-bounds read in ax25_connect()
Checks on addr_len and fsa->fsa_ax25.sax25_ndigis are insufficient. ax25_connect() can go out of bounds when fsa->fsa_ax25.sax25_ndigis equals to 7 or 8. Fix it.
This issue has been reported as a KMSAN uninit-value bug, because in such a case, ax25_connect() reaches into the uninitialized portion of the struct sockaddr_storage statically allocated in __sys_connect().
It is safe to remove fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGIS because addr_len is guaranteed to be less than or equal to sizeof(struct full_sockaddr_ax25).
--- net/ax25/af_ax25.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ax25/af_ax25.c +3 -1
@@ -1187,7 +1187,9 @@ static int __must_check ax25_connect(struct socket *sock,if (addr_len >sizeof (struct sockaddr_ax25 ) && fsa->fsa_ax25.sax25_ndigis !=0 ) {/* Valid number of digipeaters ? */ -if (fsa->fsa_ax25.sax25_ndigis <1 || fsa->fsa_ax25.sax25_ndigis >AX25_MAX_DIGIS ) { +if (fsa->fsa_ax25.sax25_ndigis <1 || + addr_len <sizeof (struct sockaddr_ax25 ) + +sizeof (ax25_address) * fsa->fsa_ax25.sax25_ndigis) { err = -EINVAL ; goto out_release; }
Signature · 1 line
2.25.1
David Miller
maintainerFrom: Peilin Ye <[email protected]>
Date: Wed, 22 Jul 2020 11:19:01 -0400
Quoted 8 lines
Checks on
addr_lenandfsa->fsa_ax25.sax25_ndigisare insufficient.ax25_connect()can go out of bounds whenfsa->fsa_ax25.sax25_ndigisequals to 7 or 8. Fix it.This issue has been reported as a KMSAN uninit-value bug, because in such a case,
ax25_connect()reaches into the uninitialized portion of thestruct sockaddr_storagestatically allocated in__sys_connect().
Quoted 7 lines
It is safe to remove
fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGISbecauseaddr_lenis guaranteed to be less than or equal tosizeof(struct full_sockaddr_ax25).Reported-by [email protected]Signed-off-by Peilin Ye <[email protected]>
Applied and queued up for -stable, thanks.
PATCH 1/1 AX.25: Prevent integer overflows in connect and sendmsg
We recently added some bounds checking in ax25_connect() and ax25_sendmsg() and we so we removed the AX25_MAX_DIGIS checks because they were no longer required.
Unfortunately, I believe they are required to prevent integer overflows so I have added them back.
---
From code review. Not tested. It should be harmless though.
net/ax25/af_ax25.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ax25/af_ax25.c +4 -1
@@ -1188,6 +1188,7 @@ static int __must_check ax25_connect(struct socket *sock, fsa->fsa_ax25.sax25_ndigis != 0) {/* Valid number of digipeaters ? */ if (fsa->fsa_ax25.sax25_ndigis <1 || + fsa->fsa_ax25.sax25_ndigis >AX25_MAX_DIGIS || addr_len <sizeof (struct sockaddr_ax25 ) +sizeof (ax25_address) * fsa->fsa_ax25.sax25_ndigis) { err = -EINVAL ;
@@ -1509,7 +1510,9 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)usax;/* Valid number of digipeaters ? */ -if (usax->sax25_ndigis <1 || addr_len <sizeof (struct sockaddr_ax25 ) + +if (usax->sax25_ndigis <1 || + usax->sax25_ndigis >AX25_MAX_DIGIS || + addr_len <sizeof (struct sockaddr_ax25 ) +sizeof (ax25_address) * usax->sax25_ndigis) { err = -EINVAL ; goto out;
Signature · 1 line
2.27.0
Re: [PATCH net] AX.25: Prevent integer overflows in connect and sendmsg
From: Dan Carpenter <[email protected]>
Date: Thu, 23 Jul 2020 17:49:57 +0300
Quoted 10 lines
We recently added some bounds checking in
ax25_connect()andax25_sendmsg()and we so we removed theAX25_MAX_DIGISchecks because they were no longer required.Unfortunately, I believe they are required to prevent integer overflows so I have added them back.
Fixes 8885bb0621f0 ("AX.25: Prevent out-of-bounds read in ax25_sendmsg()")Fixes 2f2a7ffad5c6 ("AX.25: Fix out-of-bounds read in ax25_connect()")Signed-off-by Dan Carpenter <[email protected]>
Applied, thanks Dan.
Quoted 15 lines · David Miller
From: Peilin Ye <[email protected]>
Date: Wed, 22 Jul 2020 11:19:01 -0400Quoted 12 lines
Checks on
addr_lenandfsa->fsa_ax25.sax25_ndigisare insufficient.ax25_connect()can go out of bounds whenfsa->fsa_ax25.sax25_ndigisequals to 7 or 8. Fix it.This issue has been reported as a KMSAN uninit-value bug, because in such a case,
ax25_connect()reaches into the uninitialized portion of thestruct sockaddr_storagestatically allocated in__sys_connect().It is safe to remove
fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGISbecauseaddr_lenis guaranteed to be less than or equal tosizeof(struct full_sockaddr_ax25).
Quoted 5 lines
Quoted 3 lines
Reported-by [email protected]Signed-off-by Peilin Ye <[email protected]>Applied and queued up for -stable, thanks.
Thank you for reviewing my patch!
Peilin Ye
Quoted 24 lines · Peilin Ye
Checks on
addr_lenandfsa->fsa_ax25.sax25_ndigisare insufficient.ax25_connect()can go out of bounds whenfsa->fsa_ax25.sax25_ndigisequals to 7 or 8. Fix it.This issue has been reported as a KMSAN uninit-value bug, because in such a case,
ax25_connect()reaches into the uninitialized portion of thestruct sockaddr_storagestatically allocated in__sys_connect().It is safe to remove
fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGISbecauseaddr_lenis guaranteed to be less than or equal tosizeof(struct full_sockaddr_ax25).Reported-by [email protected]Signed-off-by Peilin Ye <[email protected]>--- net/ax25/af_ax25.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/ax25/af_ax25.c +0
-0
net/ax25/af_ax25.c static int __must_check ax25_connect(struct socket *sock, · line 1192
Quoted 7 lines
net/ax25/af_ax25.c +3
-1@@ -1187,7 +1187,9 @@ static int __must_check ax25_connect(struct socket *sock,if (addr_len >sizeof (struct sockaddr_ax25 ) && fsa->fsa_ax25.sax25_ndigis !=0 ) {/* Valid number of digipeaters ? */ -if (fsa->fsa_ax25.sax25_ndigis <1 || fsa->fsa_ax25.sax25_ndigis >AX25_MAX_DIGIS ) { +if (fsa->fsa_ax25.sax25_ndigis <1 || + addr_len <sizeof (struct sockaddr_ax25 ) + +sizeof (ax25_address) * fsa->fsa_ax25.sax25_ndigis) {
The "sizeof(ax25_address) * fsa->fsa_ax25.sax25_ndigis" can have an integer overflow so you still need the "fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGIS" check.
regards,
dan carpenter
Quoted 20 lines · Dan Carpenter
Quoted 19 lines · Peilin Ye
Checks on
addr_lenandfsa->fsa_ax25.sax25_ndigisare insufficient.ax25_connect()can go out of bounds whenfsa->fsa_ax25.sax25_ndigisequals to 7 or 8. Fix it.This issue has been reported as a KMSAN uninit-value bug, because in such a case,
ax25_connect()reaches into the uninitialized portion of thestruct sockaddr_storagestatically allocated in__sys_connect().It is safe to remove
fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGISbecauseaddr_lenis guaranteed to be less than or equal tosizeof(struct full_sockaddr_ax25).Reported-by [email protected]Signed-off-by Peilin Ye <[email protected]>--- net/ax25/af_ax25.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 16 lines
net/ax25/af_ax25.c static int __must_check ax25_connect(struct socket *sock, · line 1192
Quoted 12 lines
net/ax25/af_ax25.c +3
-1@@ -1187,7 +1187,9 @@ static int __must_check ax25_connect(struct socket *sock,if (addr_len >sizeof (struct sockaddr_ax25 ) && fsa->fsa_ax25.sax25_ndigis !=0 ) {/* Valid number of digipeaters ? */ -if (fsa->fsa_ax25.sax25_ndigis <1 || fsa->fsa_ax25.sax25_ndigis >AX25_MAX_DIGIS ) { +if (fsa->fsa_ax25.sax25_ndigis <1 || + addr_len <sizeof (struct sockaddr_ax25 ) + +sizeof (ax25_address) * fsa->fsa_ax25.sax25_ndigis) {The "
sizeof(ax25_address)*fsa->fsa_ax25.sax25_ndigis" can have an integer overflow so you still need the "fsa->fsa_ax25.sax25_ndigis>AX25_MAX_DIGIS" check.
Thank you for fixing this up! I did some math but I didn't think of that. Will be more careful when removing things.
Peilin Ye
Quoted 38 lines · Peilin Ye
Quoted 20 lines · Dan Carpenter
Quoted 19 lines · Peilin Ye
Checks on
addr_lenandfsa->fsa_ax25.sax25_ndigisare insufficient.ax25_connect()can go out of bounds whenfsa->fsa_ax25.sax25_ndigisequals to 7 or 8. Fix it.This issue has been reported as a KMSAN uninit-value bug, because in such a case,
ax25_connect()reaches into the uninitialized portion of thestruct sockaddr_storagestatically allocated in__sys_connect().It is safe to remove
fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGISbecauseaddr_lenis guaranteed to be less than or equal tosizeof(struct full_sockaddr_ax25).Reported-by [email protected]Signed-off-by Peilin Ye <[email protected]>--- net/ax25/af_ax25.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Quoted 16 lines
net/ax25/af_ax25.c static int __must_check ax25_connect(struct socket *sock, · line 1192
Quoted 12 lines
net/ax25/af_ax25.c +3
-1@@ -1187,7 +1187,9 @@ static int __must_check ax25_connect(struct socket *sock,if (addr_len >sizeof (struct sockaddr_ax25 ) && fsa->fsa_ax25.sax25_ndigis !=0 ) {/* Valid number of digipeaters ? */ -if (fsa->fsa_ax25.sax25_ndigis <1 || fsa->fsa_ax25.sax25_ndigis >AX25_MAX_DIGIS ) { +if (fsa->fsa_ax25.sax25_ndigis <1 || + addr_len <sizeof (struct sockaddr_ax25 ) + +sizeof (ax25_address) * fsa->fsa_ax25.sax25_ndigis) {The "
sizeof(ax25_address)*fsa->fsa_ax25.sax25_ndigis" can have an integer overflow so you still need the "fsa->fsa_ax25.sax25_ndigis>AX25_MAX_DIGIS" check.
Quoted 2 lines
Thank you for fixing this up! I did some math but I didn't think of that. Will be more careful when removing things.
No problem. You had the right approach to look for ways to clean things up.
Your patches make me happy because you're trying to fix important bugs.
regards,
dan carpenter
Quoted 39 lines · Dan Carpenter
Quoted 38 lines · Peilin Ye
Quoted 36 lines · Dan Carpenter
Quoted 24 lines · Peilin Ye
Checks on
addr_lenandfsa->fsa_ax25.sax25_ndigisare insufficient.ax25_connect()can go out of bounds whenfsa->fsa_ax25.sax25_ndigisequals to 7 or 8. Fix it.This issue has been reported as a KMSAN uninit-value bug, because in such a case,
ax25_connect()reaches into the uninitialized portion of thestruct sockaddr_storagestatically allocated in__sys_connect().It is safe to remove
fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGISbecauseaddr_lenis guaranteed to be less than or equal tosizeof(struct full_sockaddr_ax25).Reported-by [email protected]Signed-off-by Peilin Ye <[email protected]>--- net/ax25/af_ax25.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/ax25/af_ax25.c +0
-0net/ax25/af_ax25.c static int __must_check ax25_connect(struct socket *sock, · line 1192
Quoted 7 lines
net/ax25/af_ax25.c +3
-1@@ -1187,7 +1187,9 @@ static int __must_check ax25_connect(struct socket *sock,if (addr_len >sizeof (struct sockaddr_ax25 ) && fsa->fsa_ax25.sax25_ndigis !=0 ) {/* Valid number of digipeaters ? */ -if (fsa->fsa_ax25.sax25_ndigis <1 || fsa->fsa_ax25.sax25_ndigis >AX25_MAX_DIGIS ) { +if (fsa->fsa_ax25.sax25_ndigis <1 || + addr_len <sizeof (struct sockaddr_ax25 ) + +sizeof (ax25_address) * fsa->fsa_ax25.sax25_ndigis) {The "
sizeof(ax25_address)*fsa->fsa_ax25.sax25_ndigis" can have an integer overflow so you still need the "fsa->fsa_ax25.sax25_ndigis>AX25_MAX_DIGIS" check.
Quoted 7 lines
Quoted 2 lines
Thank you for fixing this up! I did some math but I didn't think of that. Will be more careful when removing things.
No problem. You had the right approach to look for ways to clean things up.
Your patches make me happy because you're trying to fix important bugs.
It is very encouraging to hear that! I will try to do what I can do.
Thank you,
Peilin Ye
Quoted 39 lines · Dan Carpenter
Quoted 36 lines · Peilin Ye
Quoted 20 lines · Dan Carpenter
Quoted 19 lines · Peilin Ye
Checks on
addr_lenandfsa->fsa_ax25.sax25_ndigisare insufficient.ax25_connect()can go out of bounds whenfsa->fsa_ax25.sax25_ndigisequals to 7 or 8. Fix it.This issue has been reported as a KMSAN uninit-value bug, because in such a case,
ax25_connect()reaches into the uninitialized portion of thestruct sockaddr_storagestatically allocated in__sys_connect().It is safe to remove
fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGISbecauseaddr_lenis guaranteed to be less than or equal tosizeof(struct full_sockaddr_ax25).Reported-by [email protected]Signed-off-by Peilin Ye <[email protected]>--- net/ax25/af_ax25.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Quoted 15 lines
net/ax25/af_ax25.c static int __must_check ax25_connect(struct socket *sock, · line 1192
Quoted 12 lines
net/ax25/af_ax25.c +3
-1@@ -1187,7 +1187,9 @@ static int __must_check ax25_connect(struct socket *sock,if (addr_len >sizeof (struct sockaddr_ax25 ) && fsa->fsa_ax25.sax25_ndigis !=0 ) {/* Valid number of digipeaters ? */ -if (fsa->fsa_ax25.sax25_ndigis <1 || fsa->fsa_ax25.sax25_ndigis >AX25_MAX_DIGIS ) { +if (fsa->fsa_ax25.sax25_ndigis <1 || + addr_len <sizeof (struct sockaddr_ax25 ) + +sizeof (ax25_address) * fsa->fsa_ax25.sax25_ndigis) {The "
sizeof(ax25_address)*fsa->fsa_ax25.sax25_ndigis" can have an integer overflow so you still need the "fsa->fsa_ax25.sax25_ndigis>AX25_MAX_DIGIS" check.Quoted 2 lines
Thank you for fixing this up! I did some math but I didn't think of that. Will be more careful when removing things.
Quoted 7 lines
No problem. You had the right approach to look for ways to clean things up.
Your patches make me happy because you're trying to fix important bugs.
regards,
dan carpenter
As a long-term user (25 years) of kernel ax25 I appreciate any and all efforts to improve the code (which I mostly don't understand), and I applaud those individuals rising to the task.
Thanks guys (and gals).
Ray vk2tv