credentials link
This commit is contained in:
		
							parent
							
								
									29faf5bb06
								
							
						
					
					
						commit
						fe03298689
					
				@ -11,7 +11,7 @@ sudo insmod sumo.ko  # install
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# How it works
 | 
					# How it works
 | 
				
			||||||
 | 
					
 | 
				
			||||||
In it's `init()` function, *sumo* kernel module creates `/proc/sumo` file and waits for PID to be written. Afterwards, it fetches instance of a `task_struct` [kernel structure](https://medium.com/@boutnaru/linux-kernel-task-struct-829f51d97275) associated with the given PID and modifies its values accordingly.
 | 
					In it's `init()` function, *sumo* kernel module creates `/proc/sumo` file and waits for PID to be written. Afterwards, it fetches instance of a `task_struct` [kernel structure](https://medium.com/@boutnaru/linux-kernel-task-struct-829f51d97275) associated with the given PID and modifies its values accordingly. The main point of interest is the data stored in [credentials structure](https://docs.kernel.org/security/credentials.html).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```text
 | 
					```text
 | 
				
			||||||
sumo         __        SUdo
 | 
					sumo         __        SUdo
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										18
									
								
								sumo.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								sumo.c
									
									
									
									
									
								
							@ -4,10 +4,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <linux/proc_fs.h>
 | 
					#include <linux/proc_fs.h>
 | 
				
			||||||
#include <linux/fs.h>
 | 
					#include <linux/fs.h>
 | 
				
			||||||
#include <linux/uaccess.h>
 | 
					// #include <linux/uaccess.h>
 | 
				
			||||||
#include <linux/seq_file.h>
 | 
					// #include <linux/seq_file.h>
 | 
				
			||||||
#include <linux/sched.h>
 | 
					// #include <linux/sched.h>
 | 
				
			||||||
#include <linux/capability.h>
 | 
					// #include <linux/capability.h>
 | 
				
			||||||
#include <linux/cred.h>
 | 
					#include <linux/cred.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -40,17 +40,17 @@ MODULE_DESCRIPTION("Grant root access right to the process by PID");
 | 
				
			|||||||
///////////////////////////////////////////////////////////////////////////////
 | 
					///////////////////////////////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void set_task_uids_gids_to_zero(struct task_struct *task)
 | 
					void set_task_uids_gids_to_zero(struct task_struct *task)
 | 
				
			||||||
{
 | 
					  {
 | 
				
			||||||
  struct cred *_cred;
 | 
					  struct cred *_cred;
 | 
				
			||||||
  //struct real_cred *_real_cred;
 | 
					  //struct real_cred *_real_cred;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Safely access cred and real_cred using rcu_dereference
 | 
					  // Safely access cred and real_cred using rcu_dereference
 | 
				
			||||||
  _cred = (struct cred *)rcu_dereference(task->cred);
 | 
					  _cred = (struct cred *)rcu_dereference(task->cred);
 | 
				
			||||||
  //_real_cred = (struct cred *)rcu_dereference(task->real_cred);
 | 
					  //_real_cred = (struct cred *)rcu_dereference(task->real_cred);
 | 
				
			||||||
	if (_cred == NULL) {
 | 
					  if (_cred == NULL) {
 | 
				
			||||||
	  pr_err(MTAG "Task creds are null %d\n", task->pid);
 | 
					    pr_err(MTAG "Task creds are null %d\n", task->pid);
 | 
				
			||||||
		return;
 | 
					    return;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Update UIDs to zero
 | 
					  // Update UIDs to zero
 | 
				
			||||||
  _cred->uid.val = 0;
 | 
					  _cred->uid.val = 0;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user