title: Linux kernel alloc cache to remove const warning
body: <p>My goal is to write a fonction in a kernel module that allow to obtain root access.
  At original time I've got this :</p>
  
  <pre><code>struct task_struct *cur_task;
  struct cred *credz;
  /*obtain root access*/
  cur_task=current;
  credz=cur_task-&gt;cred;
  credz-&gt;uid=0;
  credz-&gt;gid=0;
  credz-&gt;suid=0;
  credz-&gt;sgid=0;
  credz-&gt;euid=0;
  credz-&gt;egid=0; 
  </code></pre>
  
  <p>It works but I try to remove the warning about const variable.
  So I try a memcopy to bypass it. But i have got a kernel panic.</p>
  
  <p>I think my error is memory allocation (kmem cache)</p>
  
  <pre><code>static struct kmem_cache *cred_jar; //global
  
  char func(void){
          struct task_struct *cur_task;
          const struct cred *old;
          struct cred *credz;
  
          cred_jar = kmem_cache_create("cred_jar", sizeof(struct cred), 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
          credz = kmem_cache_alloc(cred_jar, GFP_KERNEL);
          if (!credz){
  
              return 0;
          }
          /* obtain root access in shell*/
          cur_task=current;
          /**/
          old = cur_task-&gt;cred;
  
          /* remove warning const */
          memcpy(credz, old, sizeof(struct cred));
          credz-&gt;uid=0;
          credz-&gt;gid=0;
          credz-&gt;suid=0;
          credz-&gt;sgid=0;
          credz-&gt;euid=0;
          credz-&gt;egid=0; 
          cur_task-&gt;cred=credz;
          kfree(old);
  }
  </code></pre>
  
  <p>If you have any idea to correct it, I'm interested.</p>