[PATCH] cred: Use RCU primitives to access RCU pointers

Amol Grover
2020-01-28T07:28:56Z

task_struct.cred and task_struct.real_cred are annotated by __rcu,
hence use rcu_access_pointer to access them.

Fixes the following sparse errors:
kernel/cred.c:144:9: error: incompatible types in comparison expression
(different address spaces):
kernel/cred.c:144:9: struct cred *
kernel/cred.c:144:9: struct cred const [noderef] <asn:4> *
kernel/cred.c:145:9: error: incompatible types in comparison expression
(different address spaces):
kernel/cred.c:145:9: struct cred *
kernel/cred.c:145:9: struct cred const [noderef] <asn:4> *

Signed-off-by: Amol Grover <frextrite@gmail.com>
---
kernel/cred.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/cred.c b/kernel/cred.c
index 809a985b1793..3043c8e1544d 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -141,8 +141,8 @@ void __put_cred(struct cred *cred)
cred->magic = CRED_MAGIC_DEAD;
cred->put_addr = __builtin_return_address(0);
#endif
- BUG_ON(cred == current->cred);
- BUG_ON(cred == current->real_cred);
+ BUG_ON(cred == rcu_access_pointer(current->cred));
+ BUG_ON(cred == rcu_access_pointer(current->real_cred));

if (cred->non_rcu)
put_cred_rcu(&cred->rcu);
--
2.24.1