私の目標は、ルート アクセスを取得できるようにする関数をカーネル モジュールに記述することです。元の時間に私はこれを持っています:
struct task_struct *cur_task;
struct cred *credz;
/*obtain root access*/
cur_task=current;
credz=cur_task->cred;
credz->uid=0;
credz->gid=0;
credz->suid=0;
credz->sgid=0;
credz->euid=0;
credz->egid=0;
動作しますが、 const 変数に関する警告を削除しようとしています。だから私はそれをバイパスするために memcopy を試みます。しかし、カーネルパニックが発生しました。
私のエラーはメモリ割り当て(kmemキャッシュ)だと思います
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->cred;
/* remove warning const */
memcpy(credz, old, sizeof(struct cred));
credz->uid=0;
credz->gid=0;
credz->suid=0;
credz->sgid=0;
credz->euid=0;
credz->egid=0;
cur_task->cred=credz;
kfree(old);
}
それを修正するアイデアがあれば、私は興味があります。