[PATCH] Change MPI alloc from GFP_KERNEL to GFP_ATOMIC
From: Shaun Tancheff
Date: Fri Jul 29 2016 - 13:49:18 EST
Running Ubuntu 14.04 for testing against 4.8 merge window I am getting.
One quick fix is to change GFP_KERNEL to GFP_ATOMIC.
BUG: sleeping function called from invalid context at mm/slab.h:393
in_atomic(): 1, irqs_disabled(): 0, pid: 594, name: modprobe
no locks held by modprobe/594.
CPU: 1 PID: 594 Comm: modprobe Not tainted 4.7.0-zdm #64
Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
0000000000000000 ffff8ef5d4e5b978 ffffffff8b5eded3 ffff8ef5d9021940
ffffffff8bee5c08 ffff8ef5d4e5b9a0 ffffffff8b0b5109 ffffffff8bee5c08
0000000000000189 0000000000000000 ffff8ef5d4e5b9c8 ffffffff8b0b5209
Call Trace:
[<ffffffff8b5eded3>] dump_stack+0x85/0xc2
[<ffffffff8b0b5109>] ___might_sleep+0x179/0x230
[<ffffffff8b0b5209>] __might_sleep+0x49/0x80
[<ffffffff8b222eca>] kmem_cache_alloc_trace+0x1ba/0x2f0
[<ffffffff8b625180>] ? mpi_alloc+0x20/0x80
[<ffffffff8b625180>] mpi_alloc+0x20/0x80
[<ffffffff8b622ca7>] mpi_read_raw_from_sgl+0xc7/0x1d0
[<ffffffff8b5a06e7>] rsa_verify+0x57/0xd0
[<ffffffff8b5a0a90>] ? pkcs1pad_sg_set_buf+0x40/0xb0
[<ffffffff8b5a0d2b>] pkcs1pad_verify+0xbb/0x100
[<ffffffff8b5abb80>] public_key_verify_signature+0x1c0/0x2a0
[<ffffffff8b0e25e0>] ? debug_check_no_locks_freed+0xd0/0x160
[<ffffffff8b5abc75>] public_key_verify_signature_2+0x15/0x20
[<ffffffff8b5ab8bc>] verify_signature+0x3c/0x50
[<ffffffff8b5adc1a>] pkcs7_validate_trust+0x1fa/0x260
[<ffffffff8b1ad5cd>] verify_pkcs7_signature+0x7d/0x100
[<ffffffff8b12ebdc>] mod_verify_sig+0x7c/0xb0
[<ffffffff8b12b890>] load_module+0x170/0x2ac0
[<ffffffff8b25058d>] ? __vfs_read+0xbd/0x110
[<ffffffff8b594b1d>] ? ima_post_read_file+0x7d/0xa0
[<ffffffff8b2571f1>] ? kernel_read_file+0x191/0x1b0
[<ffffffff8b12e433>] SYSC_finit_module+0xc3/0xf0
[<ffffffff8b12e47e>] SyS_finit_module+0xe/0x10
[<ffffffff8ba6fe80>] entry_SYSCALL_64_fastpath+0x23/0xc1
Signed-off-by: Shaun Tancheff <shaun.tancheff@xxxxxxxxxxx>
---
lib/mpi/mpiutil.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/mpi/mpiutil.c b/lib/mpi/mpiutil.c
index 314f4df..420ace3 100644
--- a/lib/mpi/mpiutil.c
+++ b/lib/mpi/mpiutil.c
@@ -31,7 +31,7 @@ MPI mpi_alloc(unsigned nlimbs)
{
MPI a;
- a = kmalloc(sizeof *a, GFP_KERNEL);
+ a = kmalloc(sizeof *a, GFP_ATOMIC);
if (!a)
return a;
@@ -61,7 +61,7 @@ mpi_ptr_t mpi_alloc_limb_space(unsigned nlimbs)
if (!len)
return NULL;
- return kmalloc(len, GFP_KERNEL);
+ return kmalloc(len, GFP_ATOMIC);
}
void mpi_free_limb_space(mpi_ptr_t a)
@@ -91,14 +91,14 @@ int mpi_resize(MPI a, unsigned nlimbs)
return 0; /* no need to do it */
if (a->d) {
- p = kmalloc(nlimbs * sizeof(mpi_limb_t), GFP_KERNEL);
+ p = kmalloc(nlimbs * sizeof(mpi_limb_t), GFP_ATOMIC);
if (!p)
return -ENOMEM;
memcpy(p, a->d, a->alloced * sizeof(mpi_limb_t));
kzfree(a->d);
a->d = p;
} else {
- a->d = kzalloc(nlimbs * sizeof(mpi_limb_t), GFP_KERNEL);
+ a->d = kzalloc(nlimbs * sizeof(mpi_limb_t), GFP_ATOMIC);
if (!a->d)
return -ENOMEM;
}
--
2.8.1