netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net:qrtr: fix atomic idr allocation in qrtr_port_assign()
@ 2021-03-27 14:07 Du Cheng
  2021-03-27 14:12 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 9+ messages in thread
From: Du Cheng @ 2021-03-27 14:07 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski
  Cc: netdev, Greg Kroah-Hartman, Shuah Khan, Du Cheng,
	syzbot+3eec59e770685e3dc879

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

Reported-by: syzbot+3eec59e770685e3dc879@syzkaller.appspotmail.com
Signed-off-by: Du Cheng <ducheng2@gmail.com>
---
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(+)

diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index edb6ac17ceca..6361f169490e 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -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;
 	}
-- 
2.27.0


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

end of thread, other threads:[~2021-03-29 11:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-27 14:07 [PATCH v2] net:qrtr: fix atomic idr allocation in qrtr_port_assign() Du Cheng
2021-03-27 14:12 ` Greg Kroah-Hartman
2021-03-27 14:25   ` Du Cheng
2021-03-27 14:31     ` Greg Kroah-Hartman
2021-03-27 15:51       ` Matthew Wilcox
2021-03-28  6:56         ` Greg Kroah-Hartman
2021-03-28 10:04           ` Matthew Wilcox
2021-03-29 10:55             ` Du Cheng
2021-03-29 11:09               ` Manivannan Sadhasivam

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).