Oops (request_key_auth_describe) while running cve-2016-7042 from LTP
Subsystems (2)
Quoted 5 lines · On Fri, 30 Aug 2019 12:18:07 +0530 Sachin Sant wrote:
[ 8074.351033] BUG: Kernel NULL pointer dereference at 0x00000038 [ 8074.351046] Faulting instruction address: 0xc0000000004ddf30 [ 8074.351052] Oops: Kernel access of bad area, sig: 11 [#1] [ 8074.351056] LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries
Add rcu gp.
security/keys/request_key_auth.c +8 -1
@@ -64,12 +64,19 @@ static int request_key_auth_instantiate(static void request_key_auth_describe (const struct key *key,struct seq_file *m) { -struct request_key_auth *rka =dereference_key_rcu (key); +struct request_key_auth *rka; + +rcu_read_lock (); + rka =dereference_key_rcu (key); +if (!rka) + goto out;seq_puts (m,"key:" );seq_puts (m, key->description);if (key_is_positive (key))seq_printf (m," pid:%d ci:%zu" , rka->pid, rka->callout_len); +out: +rcu_read_unlock (); }/*
Sachin Sant
Tested-byQuoted 18 lines · Hillf Danton
Quoted 5 lines · On Fri, 30 Aug 2019 12:18:07 +0530 Sachin Sant wrote:
[ 8074.351033] BUG: Kernel NULL pointer dereference at 0x00000038 [ 8074.351046] Faulting instruction address: 0xc0000000004ddf30 [ 8074.351052] Oops: Kernel access of bad area, sig: 11 [#1] [ 8074.351056] LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeriesAdd rcu gp.
security/keys/request_key_auth.c +0
-0@@ -64,12 +64,19 @@ static int request_key_auth_instantiate( static void request_key_auth_describe(const struct key *key,
security/keys/request_key_auth.c static int request_key_auth_instantiate( · line 73
Quoted 10 lines
security/keys/request_key_auth.c +6
-1struct seq_file *m) { -struct request_key_auth *rka =dereference_key_rcu (key); +struct request_key_auth *rka; + +rcu_read_lock (); + rka =dereference_key_rcu (key); +if (!rka) + goto out;
Thanks for the patch. Works for me. Test ran fine without any problems.
Thanks
-Sachin
David Howells
maintainersecurity/keys/request_key_auth.c static int request_key_auth_instantiate( · line 70
Quoted 5 lines · Hillf Danton
security/keys/request_key_auth.c +4
-1-struct request_key_auth *rka =dereference_key_rcu (key); +struct request_key_auth *rka; + +rcu_read_lock (); + rka =dereference_key_rcu (key);
This shouldn't help as the caller, proc_keys_show(), is holding the RCU read lock across the call. The end of the function reads:
if (key->type->describe) key->type->describe(key, m); seq_putc(m, '\n'); rcu_read_unlock(); return 0; }
and the documentation says "This method will be called with the RCU read lock held".
I suspect the actual bugfix is this bit:
security/keys/request_key_auth.c static int request_key_auth_instantiate( · line 72
Quoted 2 lines
security/keys/request_key_auth.c +2
-0+if (!rka) + goto out;
David
David Howells
maintainerQuoted 3 lines · Hillf Danton
1, callee has no pre defined duty to help caller in general; they should not try to do anything, however, to help their callers in principle due to limited info on their hands IMO.
Ah, no. It's entirely reasonable for an API to specify that one of its methods will be called with one or more locks held - and that the method must be aware of this and may make use of this.
Quoted 2 lines
3, no comment can be found in
security/keys/request_key_auth.cabout the rcu already documented.
There is API documentation in Documentation/security/keys/core.rst. If you look at about line 1538 onwards:
* ``void (*describe)(const struct key *key, struct seq_file *p);``
This method is optional. It is called during /proc/keys reading to summarise a key's description and payload in text form.
This method will be called with the RCU read lock held. rcu_dereference() should be used to read the payload pointer if the payload is to be accessed. key->datalen cannot be trusted to stay consistent with the contents of the payload.
The description will not change, though the key's state may.
It is not safe to sleep in this method; the RCU read lock is held by the caller.
David
Quoted 14 lines · David Howells
security/keys/request_key_auth.c static int request_key_auth_instantiate( · line 70
Quoted 5 lines · Hillf Danton
security/keys/request_key_auth.c +4
-1-struct request_key_auth *rka =dereference_key_rcu (key); +struct request_key_auth *rka; + +rcu_read_lock (); + rka =dereference_key_rcu (key);This shouldn't help as the caller,
proc_keys_show(), is holding the RCU read lock across the call. The end of the function reads:
and the documentation says "This method will be called with the RCU read lock held".
1, callee has no pre defined duty to help caller in general; they should not try to do anything, however, to help their callers in principle due to limited info on their hands IMO.
2, uses of rcu can be nested.
3, no comment can be found in security/keys/request_key_auth.c about the rcu already documented.
4, the newly added rcu can avoid incidental messup anywhere else.
Hillf
Quoted 8 lines · David Howells
Quoted 3 lines
1, callee has no pre defined duty to help caller in general; they should not try to do anything, however, to help their callers in principle due to limited info on their hands IMO.
Ah, no. It's entirely reasonable for an API to specify that one of its methods will be called with one or more locks held - and that the method must be aware of this and may make use of this.
Fair and clear.
Thanks
Hillf