net:qrtr: fix atomic idr allocation in qrtr_port_assign()
Subsystems (3)
PATCH v2 1/1 net:qrtr: fix atomic idr allocation in qrtr_port_assign()
add idr_preload() and idr_preload_end() around idr_alloc_u32(GFP_ATOMIC) due to internal use of per_cpu variables, which requires preemption disabling/enabling.
reported as "BUG: "using smp_processor_id() in preemptible" by syzkaller
---
changelog
v1: change to GFP_KERNEL for idr_alloc_u32() but might sleep
v2: revert to GFP_ATOMIC but add preemption disable/enable protection
net/qrtr/qrtr.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/qrtr/qrtr.c +6 -0
@@ -722,17 +722,23 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)mutex_lock (&qrtr_port_lock);if (!*port) { min_port =QRTR_MIN_EPH_SOCKET ; +idr_preload (GFP_ATOMIC ); rc =idr_alloc_u32 (&qrtr_ports, ipc, &min_port,QRTR_MAX_EPH_SOCKET ,GFP_ATOMIC ); +idr_preload_end ();if (!rc) *port = min_port; }else if (*port <QRTR_MIN_EPH_SOCKET && !capable (CAP_NET_ADMIN )) { rc = -EACCES ; }else if (*port ==QRTR_PORT_CTRL ) { min_port =0 ; +idr_preload (GFP_ATOMIC ); rc =idr_alloc_u32 (&qrtr_ports, ipc, &min_port,0 ,GFP_ATOMIC ); +idr_preload_end (); }else { min_port = *port; +idr_preload (GFP_ATOMIC ); rc =idr_alloc_u32 (&qrtr_ports, ipc, &min_port, *port,GFP_ATOMIC ); +idr_preload_end ();if (!rc) *port = min_port; }
Signature · 1 line
2.27.0
Adding the xarray maintainer...
Quoted 21 lines · Du Cheng
add
idr_preload()andidr_preload_end()aroundidr_alloc_u32(GFP_ATOMIC)due to internal use ofper_cpuvariables, which requires preemption disabling/enabling.reported as "BUG: "using
smp_processor_id()in preemptible" by syzkallerReported-by [email protected]Signed-off-by Du Cheng <[email protected]>---
changelog
v1: change toGFP_KERNELforidr_alloc_u32()but might sleep
v2: revert toGFP_ATOMICbut add preemption disable/enable protectionnet/qrtr/qrtr.c | 6 ++++++ 1 file changed, 6 insertions(+)net/qrtr/qrtr.c +0
-0
net/qrtr/qrtr.c static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) · line 727
Quoted 6 lines
net/qrtr/qrtr.c +2
-0@@ -722,17 +722,23 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)mutex_lock (&qrtr_port_lock);if (!*port) { min_port =QRTR_MIN_EPH_SOCKET ; +idr_preload (GFP_ATOMIC ); rc =idr_alloc_u32 (&qrtr_ports, ipc, &min_port,QRTR_MAX_EPH_SOCKET ,GFP_ATOMIC ); +idr_preload_end ();
This seems "odd" to me. We are asking idr_alloc_u32() to abide by GFP_ATOMIC, so why do we need to "preload" it with the same type of allocation?
Is there something in the idr/radix/xarray code that can't really handle GFP_ATOMIC during a "normal" idr allocation that is causing this warning to be hit? Why is this change the "correct" one?
thanks,
greg k-h
Quoted 35 lines · Greg Kroah-Hartman
Adding the xarray maintainer...
Quoted 21 lines · Du Cheng
add
idr_preload()andidr_preload_end()aroundidr_alloc_u32(GFP_ATOMIC)due to internal use ofper_cpuvariables, which requires preemption disabling/enabling.reported as "BUG: "using
smp_processor_id()in preemptible" by syzkallerReported-by [email protected]Signed-off-by Du Cheng <[email protected]>---
changelog
v1: change toGFP_KERNELforidr_alloc_u32()but might sleep
v2: revert toGFP_ATOMICbut add preemption disable/enable protectionnet/qrtr/qrtr.c | 6 ++++++ 1 file changed, 6 insertions(+)net/qrtr/qrtr.c +0
-0net/qrtr/qrtr.c static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) · line 727
Quoted 6 lines
net/qrtr/qrtr.c +2
-0@@ -722,17 +722,23 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)mutex_lock (&qrtr_port_lock);if (!*port) { min_port =QRTR_MIN_EPH_SOCKET ; +idr_preload (GFP_ATOMIC ); rc =idr_alloc_u32 (&qrtr_ports, ipc, &min_port,QRTR_MAX_EPH_SOCKET ,GFP_ATOMIC ); +idr_preload_end ();This seems "odd" to me. We are asking
idr_alloc_u32()to abide byGFP_ATOMIC, so why do we need to "preload" it with the same type of allocation?
Quoted 7 lines
Is there something in the idr/radix/xarray code that can't really handle
GFP_ATOMICduring a "normal" idr allocation that is causing this warning to be hit? Why is this change the "correct" one?thanks,
greg k-h
From the comment above idr_preload() in lib/radix-tree.c:1460
/**
* idr_preload - preload for idr_alloc()
* @gfp_mask: allocation mask to use for preloading
*
* Preallocate memory to use for the next call to idr_alloc(). This function
* returns with preemption disabled. It will be enabled by idr_preload_end(). */
idr_alloc is a very simple wrapper around idr_alloc_u32().
On top of radix_tree_node_alloc() which is called by idr_alloc_u32(), there is this comment at line 244 in the same radix-tree.c
/*
* This assumes that the caller has performed appropriate preallocation, and
* that the caller has pinned this thread of control to the current CPU. */
Therefore the preload/preload_end are necessary, or at least should have preemption disabled
Regards,
Du Cheng
Quoted 63 lines · Du Cheng
Quoted 39 lines · Greg Kroah-Hartman
Adding the xarray maintainer...
Quoted 21 lines · Du Cheng
add
idr_preload()andidr_preload_end()aroundidr_alloc_u32(GFP_ATOMIC)due to internal use ofper_cpuvariables, which requires preemption disabling/enabling.reported as "BUG: "using
smp_processor_id()in preemptible" by syzkallerReported-by [email protected]Signed-off-by Du Cheng <[email protected]>---
changelog
v1: change toGFP_KERNELforidr_alloc_u32()but might sleep
v2: revert toGFP_ATOMICbut add preemption disable/enable protectionnet/qrtr/qrtr.c | 6 ++++++ 1 file changed, 6 insertions(+)net/qrtr/qrtr.c +0
-0net/qrtr/qrtr.c static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) · line 727
Quoted 6 lines
net/qrtr/qrtr.c +2
-0@@ -722,17 +722,23 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)mutex_lock (&qrtr_port_lock);if (!*port) { min_port =QRTR_MIN_EPH_SOCKET ; +idr_preload (GFP_ATOMIC ); rc =idr_alloc_u32 (&qrtr_ports, ipc, &min_port,QRTR_MAX_EPH_SOCKET ,GFP_ATOMIC ); +idr_preload_end ();This seems "odd" to me. We are asking
idr_alloc_u32()to abide byGFP_ATOMIC, so why do we need to "preload" it with the same type of allocation?Is there something in the idr/radix/xarray code that can't really handle
GFP_ATOMICduring a "normal" idr allocation that is causing this warning to be hit? Why is this change the "correct" one?Quoted 6 lines
thanks,
greg k-h
From the comment above
idr_preload()inlib/radix-tree.c:1460/**
*idr_preload- preload foridr_alloc()
* @gfp_mask: allocation mask to use for preloading
*
* Preallocate memory to use for the next call toidr_alloc(). This function
* returns with preemption disabled. It will be enabled byidr_preload_end(). */
idr_allocis a very simple wrapper aroundidr_alloc_u32().On top of
radix_tree_node_alloc()which is called byidr_alloc_u32(), there is this comment at line 244 in the sameradix-tree.c
/*
* This assumes that the caller has performed appropriate preallocation, and
* that the caller has pinned this thread of control to the current CPU. */
Quoted 2 lines
Therefore the preload/preload_end are necessary, or at least should have preemption disabled
Ah, so it's disabling preemption that is the key here. Still odd, why is GFP_ATOMIC not sufficient in a normal idr_alloc() call to keep things from doing stuff like this? Feels like a lot of "internal knowledge" is needed here to use this api properly...
Matthew, is the above change really correct?
thanks,
greg k-h
Quoted 67 lines · Greg Kroah-Hartman
Quoted 63 lines · Du Cheng
Quoted 39 lines · Greg Kroah-Hartman
Adding the xarray maintainer...
Quoted 21 lines · Du Cheng
add
idr_preload()andidr_preload_end()aroundidr_alloc_u32(GFP_ATOMIC)due to internal use ofper_cpuvariables, which requires preemption disabling/enabling.reported as "BUG: "using
smp_processor_id()in preemptible" by syzkallerReported-by [email protected]Signed-off-by Du Cheng <[email protected]>---
changelog
v1: change toGFP_KERNELforidr_alloc_u32()but might sleep
v2: revert toGFP_ATOMICbut add preemption disable/enable protectionnet/qrtr/qrtr.c | 6 ++++++ 1 file changed, 6 insertions(+)net/qrtr/qrtr.c +0
-0net/qrtr/qrtr.c static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) · line 727
Quoted 6 lines
net/qrtr/qrtr.c +2
-0@@ -722,17 +722,23 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)mutex_lock (&qrtr_port_lock);if (!*port) { min_port =QRTR_MIN_EPH_SOCKET ; +idr_preload (GFP_ATOMIC ); rc =idr_alloc_u32 (&qrtr_ports, ipc, &min_port,QRTR_MAX_EPH_SOCKET ,GFP_ATOMIC ); +idr_preload_end ();This seems "odd" to me. We are asking
idr_alloc_u32()to abide byGFP_ATOMIC, so why do we need to "preload" it with the same type of allocation?Is there something in the idr/radix/xarray code that can't really handle
GFP_ATOMICduring a "normal" idr allocation that is causing this warning to be hit? Why is this change the "correct" one?Quoted 6 lines
thanks,
greg k-h
From the comment above
idr_preload()inlib/radix-tree.c:1460/**
*idr_preload- preload foridr_alloc()
* @gfp_mask: allocation mask to use for preloading
*
* Preallocate memory to use for the next call toidr_alloc(). This function
* returns with preemption disabled. It will be enabled byidr_preload_end(). */
idr_allocis a very simple wrapper aroundidr_alloc_u32().On top of
radix_tree_node_alloc()which is called byidr_alloc_u32(), there is this comment at line 244 in the sameradix-tree.c
/*
* This assumes that the caller has performed appropriate preallocation, and
* that the caller has pinned this thread of control to the current CPU. */Quoted 2 lines
Therefore the preload/preload_end are necessary, or at least should have preemption disabled
Quoted 6 lines
Ah, so it's disabling preemption that is the key here. Still odd, why is
GFP_ATOMICnot sufficient in a normalidr_alloc()call to keep things from doing stuff like this? Feels like a lot of "internal knowledge" is needed here to use this api properly...Matthew, is the above change really correct?
No.
https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/[email protected]/
Quoted 73 lines · Matthew Wilcox
Quoted 72 lines · Greg Kroah-Hartman
Quoted 63 lines · Du Cheng
Quoted 39 lines · Greg Kroah-Hartman
Adding the xarray maintainer...
Quoted 21 lines · Du Cheng
add
idr_preload()andidr_preload_end()aroundidr_alloc_u32(GFP_ATOMIC)due to internal use ofper_cpuvariables, which requires preemption disabling/enabling.reported as "BUG: "using
smp_processor_id()in preemptible" by syzkallerReported-by [email protected]Signed-off-by Du Cheng <[email protected]>---
changelog
v1: change toGFP_KERNELforidr_alloc_u32()but might sleep
v2: revert toGFP_ATOMICbut add preemption disable/enable protectionnet/qrtr/qrtr.c | 6 ++++++ 1 file changed, 6 insertions(+)net/qrtr/qrtr.c +0
-0net/qrtr/qrtr.c static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) · line 727
Quoted 6 lines
net/qrtr/qrtr.c +2
-0@@ -722,17 +722,23 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)mutex_lock (&qrtr_port_lock);if (!*port) { min_port =QRTR_MIN_EPH_SOCKET ; +idr_preload (GFP_ATOMIC ); rc =idr_alloc_u32 (&qrtr_ports, ipc, &min_port,QRTR_MAX_EPH_SOCKET ,GFP_ATOMIC ); +idr_preload_end ();This seems "odd" to me. We are asking
idr_alloc_u32()to abide byGFP_ATOMIC, so why do we need to "preload" it with the same type of allocation?Is there something in the idr/radix/xarray code that can't really handle
GFP_ATOMICduring a "normal" idr allocation that is causing this warning to be hit? Why is this change the "correct" one?Quoted 6 lines
thanks,
greg k-h
From the comment above
idr_preload()inlib/radix-tree.c:1460/**
*idr_preload- preload foridr_alloc()
* @gfp_mask: allocation mask to use for preloading
*
* Preallocate memory to use for the next call toidr_alloc(). This function
* returns with preemption disabled. It will be enabled byidr_preload_end(). */
idr_allocis a very simple wrapper aroundidr_alloc_u32().On top of
radix_tree_node_alloc()which is called byidr_alloc_u32(), there is this comment at line 244 in the sameradix-tree.c
/*
* This assumes that the caller has performed appropriate preallocation, and
* that the caller has pinned this thread of control to the current CPU. */Quoted 2 lines
Therefore the preload/preload_end are necessary, or at least should have preemption disabled
Ah, so it's disabling preemption that is the key here. Still odd, why is
GFP_ATOMICnot sufficient in a normalidr_alloc()call to keep things from doing stuff like this? Feels like a lot of "internal knowledge" is needed here to use this api properly...
Quoted 8 lines
Quoted 1 line
Matthew, is the above change really correct?
No.
https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/[email protected]/
Ok, it looks like this code is just abandonded, should we remove it entirely as no one wants to maintain it?
thanks,
greg k-h
Quoted 78 lines · Greg Kroah-Hartman
Quoted 77 lines · Matthew Wilcox
Quoted 67 lines · Greg Kroah-Hartman
Quoted 63 lines · Du Cheng
Quoted 39 lines · Greg Kroah-Hartman
Adding the xarray maintainer...
Quoted 21 lines · Du Cheng
add
idr_preload()andidr_preload_end()aroundidr_alloc_u32(GFP_ATOMIC)due to internal use ofper_cpuvariables, which requires preemption disabling/enabling.reported as "BUG: "using
smp_processor_id()in preemptible" by syzkallerReported-by [email protected]Signed-off-by Du Cheng <[email protected]>---
changelog
v1: change toGFP_KERNELforidr_alloc_u32()but might sleep
v2: revert toGFP_ATOMICbut add preemption disable/enable protectionnet/qrtr/qrtr.c | 6 ++++++ 1 file changed, 6 insertions(+)net/qrtr/qrtr.c +0
-0net/qrtr/qrtr.c static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) · line 727
Quoted 6 lines
net/qrtr/qrtr.c +2
-0@@ -722,17 +722,23 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)mutex_lock (&qrtr_port_lock);if (!*port) { min_port =QRTR_MIN_EPH_SOCKET ; +idr_preload (GFP_ATOMIC ); rc =idr_alloc_u32 (&qrtr_ports, ipc, &min_port,QRTR_MAX_EPH_SOCKET ,GFP_ATOMIC ); +idr_preload_end ();This seems "odd" to me. We are asking
idr_alloc_u32()to abide byGFP_ATOMIC, so why do we need to "preload" it with the same type of allocation?Is there something in the idr/radix/xarray code that can't really handle
GFP_ATOMICduring a "normal" idr allocation that is causing this warning to be hit? Why is this change the "correct" one?Quoted 6 lines
thanks,
greg k-h
From the comment above
idr_preload()inlib/radix-tree.c:1460/**
*idr_preload- preload foridr_alloc()
* @gfp_mask: allocation mask to use for preloading
*
* Preallocate memory to use for the next call toidr_alloc(). This function
* returns with preemption disabled. It will be enabled byidr_preload_end(). */
idr_allocis a very simple wrapper aroundidr_alloc_u32().On top of
radix_tree_node_alloc()which is called byidr_alloc_u32(), there is this comment at line 244 in the sameradix-tree.c
/*
* This assumes that the caller has performed appropriate preallocation, and
* that the caller has pinned this thread of control to the current CPU. */Quoted 2 lines
Therefore the preload/preload_end are necessary, or at least should have preemption disabled
Quoted 6 lines
Ah, so it's disabling preemption that is the key here. Still odd, why is
GFP_ATOMICnot sufficient in a normalidr_alloc()call to keep things from doing stuff like this? Feels like a lot of "internal knowledge" is needed here to use this api properly...Matthew, is the above change really correct?
No.
Quoted 7 lines
Quoted 4 lines
https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/[email protected]/Ok, it looks like this code is just abandonded, should we remove it entirely as no one wants to maintain it?
Fine by me. I don't use it. Better to get rid of abandonware than keep a potential source of security holes.
Quoted 84 lines · Matthew Wilcox
Quoted 83 lines · Greg Kroah-Hartman
Quoted 81 lines · Matthew Wilcox
Quoted 67 lines · Greg Kroah-Hartman
Quoted 63 lines · Du Cheng
Quoted 39 lines · Greg Kroah-Hartman
Adding the xarray maintainer...
Quoted 21 lines · Du Cheng
add
idr_preload()andidr_preload_end()aroundidr_alloc_u32(GFP_ATOMIC)due to internal use ofper_cpuvariables, which requires preemption disabling/enabling.reported as "BUG: "using
smp_processor_id()in preemptible" by syzkallerReported-by [email protected]Signed-off-by Du Cheng <[email protected]>---
changelog
v1: change toGFP_KERNELforidr_alloc_u32()but might sleep
v2: revert toGFP_ATOMICbut add preemption disable/enable protectionnet/qrtr/qrtr.c | 6 ++++++ 1 file changed, 6 insertions(+)net/qrtr/qrtr.c +0
-0net/qrtr/qrtr.c static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) · line 727
Quoted 6 lines
net/qrtr/qrtr.c +2
-0@@ -722,17 +722,23 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)mutex_lock (&qrtr_port_lock);if (!*port) { min_port =QRTR_MIN_EPH_SOCKET ; +idr_preload (GFP_ATOMIC ); rc =idr_alloc_u32 (&qrtr_ports, ipc, &min_port,QRTR_MAX_EPH_SOCKET ,GFP_ATOMIC ); +idr_preload_end ();This seems "odd" to me. We are asking
idr_alloc_u32()to abide byGFP_ATOMIC, so why do we need to "preload" it with the same type of allocation?Is there something in the idr/radix/xarray code that can't really handle
GFP_ATOMICduring a "normal" idr allocation that is causing this warning to be hit? Why is this change the "correct" one?Quoted 6 lines
thanks,
greg k-h
From the comment above
idr_preload()inlib/radix-tree.c:1460/**
*idr_preload- preload foridr_alloc()
* @gfp_mask: allocation mask to use for preloading
*
* Preallocate memory to use for the next call toidr_alloc(). This function
* returns with preemption disabled. It will be enabled byidr_preload_end(). */
idr_allocis a very simple wrapper aroundidr_alloc_u32().On top of
radix_tree_node_alloc()which is called byidr_alloc_u32(), there is this comment at line 244 in the sameradix-tree.c
/*
* This assumes that the caller has performed appropriate preallocation, and
* that the caller has pinned this thread of control to the current CPU. */Quoted 2 lines
Therefore the preload/preload_end are necessary, or at least should have preemption disabled
Quoted 6 lines
Ah, so it's disabling preemption that is the key here. Still odd, why is
GFP_ATOMICnot sufficient in a normalidr_alloc()call to keep things from doing stuff like this? Feels like a lot of "internal knowledge" is needed here to use this api properly...Matthew, is the above change really correct?
No.
https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/[email protected]/
Quoted 5 lines
Quoted 2 lines
Ok, it looks like this code is just abandonded, should we remove it entirely as no one wants to maintain it?
Fine by me. I don't use it. Better to get rid of abandonware than keep a potential source of security holes.
Hi Manivannan,
For your information.
Regards,
Du Cheng
Quoted 37 lines · Du Cheng
Quoted 36 lines · Matthew Wilcox
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · Matthew Wilcox
Quoted 33 lines · Greg Kroah-Hartman
Quoted 32 lines · Du Cheng
Quoted 31 lines · Greg Kroah-Hartman
Adding the xarray maintainer...
Quoted 27 lines · Du Cheng
add
idr_preload()andidr_preload_end()aroundidr_alloc_u32(GFP_ATOMIC)due to internal use ofper_cpuvariables, which requires preemption disabling/enabling.reported as "BUG: "using
smp_processor_id()in preemptible" by syzkallerReported-by [email protected]Signed-off-by Du Cheng <[email protected]>---
changelog
v1: change toGFP_KERNELforidr_alloc_u32()but might sleep
v2: revert toGFP_ATOMICbut add preemption disable/enable protectionnet/qrtr/qrtr.c | 6 ++++++ 1 file changed, 6 insertions(+)net/qrtr/qrtr.c +2
-0@@ -722,17 +722,23 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)mutex_lock (&qrtr_port_lock);if (!*port) { min_port =QRTR_MIN_EPH_SOCKET ; +idr_preload (GFP_ATOMIC ); rc =idr_alloc_u32 (&qrtr_ports, ipc, &min_port,QRTR_MAX_EPH_SOCKET ,GFP_ATOMIC ); +idr_preload_end ();
[...]
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
Ok, it looks like this code is just abandonded, should we remove it entirely as no one wants to maintain it?
Fine by me. I don't use it. Better to get rid of abandonware than keep a potential source of security holes.
Hi Manivannan,
For your information.
Thanks for letting me know. I'll look into it once back to work.
Thanks,
Mani
Quoted 2 lines
Regards,
Du Cheng