netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] xfrm: validate template mode
@ 2018-09-19 19:54 Sean Tranchetti
  2018-09-24  8:03 ` Steffen Klassert
  0 siblings, 1 reply; 2+ messages in thread
From: Sean Tranchetti @ 2018-09-19 19:54 UTC (permalink / raw)
  To: netdev, steffen.klassert; +Cc: Sean Tranchetti

XFRM mode parameters passed as part of the user templates
in the IP_XFRM_POLICY are never properly validated. Passing
values other than valid XFRM modes can cause stack-out-of-bounds
reads to occur later in the XFRM processing:

[  140.535608] ================================================================
[  140.543058] BUG: KASAN: stack-out-of-bounds in xfrm_state_find+0x17e4/0x1cc4
[  140.550306] Read of size 4 at addr ffffffc0238a7a58 by task repro/5148
[  140.557369]
[  140.558927] Call trace:
[  140.558936] dump_backtrace+0x0/0x388
[  140.558940] show_stack+0x24/0x30
[  140.558946] __dump_stack+0x24/0x2c
[  140.558949] dump_stack+0x8c/0xd0
[  140.558956] print_address_description+0x74/0x234
[  140.558960] kasan_report+0x240/0x264
[  140.558963] __asan_report_load4_noabort+0x2c/0x38
[  140.558967] xfrm_state_find+0x17e4/0x1cc4
[  140.558971] xfrm_resolve_and_create_bundle+0x40c/0x1fb8
[  140.558975] xfrm_lookup+0x238/0x1444
[  140.558977] xfrm_lookup_route+0x48/0x11c
[  140.558984] ip_route_output_flow+0x88/0xc4
[  140.558991] raw_sendmsg+0xa74/0x266c
[  140.558996] inet_sendmsg+0x258/0x3b0
[  140.559002] sock_sendmsg+0xbc/0xec
[  140.559005] SyS_sendto+0x3a8/0x5a8
[  140.559008] el0_svc_naked+0x34/0x38
[  140.559009]
[  140.592245] page dumped because: kasan: bad access detected
[  140.597981] page_owner info is not active (free page?)
[  140.603267]
[  140.653503] ================================================================

Signed-off-by: Sean Tranchetti <stranche@codeaurora.org>
---
 net/xfrm/xfrm_user.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 4791aa8..ab2f280 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -1480,6 +1480,9 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)
 		    (ut[i].family != prev_family))
 			return -EINVAL;
 
+		if (ut[i].mode >= XFRM_MODE_MAX)
+			return -EINVAL;
+
 		prev_family = ut[i].family;
 
 		switch (ut[i].family) {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] xfrm: validate template mode
  2018-09-19 19:54 [PATCH net] xfrm: validate template mode Sean Tranchetti
@ 2018-09-24  8:03 ` Steffen Klassert
  0 siblings, 0 replies; 2+ messages in thread
From: Steffen Klassert @ 2018-09-24  8:03 UTC (permalink / raw)
  To: Sean Tranchetti; +Cc: netdev

On Wed, Sep 19, 2018 at 01:54:56PM -0600, Sean Tranchetti wrote:
> XFRM mode parameters passed as part of the user templates
> in the IP_XFRM_POLICY are never properly validated. Passing
> values other than valid XFRM modes can cause stack-out-of-bounds
> reads to occur later in the XFRM processing:
> 
> [  140.535608] ================================================================
> [  140.543058] BUG: KASAN: stack-out-of-bounds in xfrm_state_find+0x17e4/0x1cc4
> [  140.550306] Read of size 4 at addr ffffffc0238a7a58 by task repro/5148
> [  140.557369]
> [  140.558927] Call trace:
> [  140.558936] dump_backtrace+0x0/0x388
> [  140.558940] show_stack+0x24/0x30
> [  140.558946] __dump_stack+0x24/0x2c
> [  140.558949] dump_stack+0x8c/0xd0
> [  140.558956] print_address_description+0x74/0x234
> [  140.558960] kasan_report+0x240/0x264
> [  140.558963] __asan_report_load4_noabort+0x2c/0x38
> [  140.558967] xfrm_state_find+0x17e4/0x1cc4
> [  140.558971] xfrm_resolve_and_create_bundle+0x40c/0x1fb8
> [  140.558975] xfrm_lookup+0x238/0x1444
> [  140.558977] xfrm_lookup_route+0x48/0x11c
> [  140.558984] ip_route_output_flow+0x88/0xc4
> [  140.558991] raw_sendmsg+0xa74/0x266c
> [  140.558996] inet_sendmsg+0x258/0x3b0
> [  140.559002] sock_sendmsg+0xbc/0xec
> [  140.559005] SyS_sendto+0x3a8/0x5a8
> [  140.559008] el0_svc_naked+0x34/0x38
> [  140.559009]
> [  140.592245] page dumped because: kasan: bad access detected
> [  140.597981] page_owner info is not active (free page?)
> [  140.603267]
> [  140.653503] ================================================================
> 
> Signed-off-by: Sean Tranchetti <stranche@codeaurora.org>

Applied to the ipsec tree, thanks a lot!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-24 14:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-19 19:54 [PATCH net] xfrm: validate template mode Sean Tranchetti
2018-09-24  8:03 ` Steffen Klassert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).