PAX补丁导致nvidia显卡驱动编译不了的解决办法

本文详细介绍了在使用Gentoo-hardened内核环境下编译NVIDIA显卡驱动时遇到的pax相关错误问题,并通过提供补丁解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用的gentoo-hardened的内核,结果安装nvidia的显卡驱动,编译内核的时候报错,错误如下:

/tmp/selfgz22986/NVIDIA-Linux-x86-280.13/kernel/nv-procfs.c: In function 'nv_register_procfs':
/tmp/selfgz22986/NVIDIA-Linux-x86-280.13/kernel/nv-procfs.c:710:5: error: assignment of read-only variable 'nv_procfs_registry_fops'
/tmp/selfgz22986/NVIDIA-Linux-x86-280.13/kernel/nv-procfs.c:711:5: error: assignment of read-only variable 'nv_procfs_registry_fops'


但察看代码,nv_procfs_registry_fops就是一个很普通的静态外部变量啊!在nv_register_procfs里面修改了下read和write的值

static struct file_operations nv_procfs_registry_fops = {
    .open    = nv_procfs_open_registry,
    .release = nv_procfs_close_registry,
};

int nv_register_procfs(void)
{

    ...................

    /*
     * entry->proc_fops originally points to a constant
     * structure, so to add more methods for the
     * binary registry write path, we need to replace the
     * said entry->proc_fops with a new fops structure.
     * However, in preparation for this, we need to preserve
     * the procfs read() and write() operations.
     */

    nv_procfs_registry_fops.read = entry->proc_fops->read;
    nv_procfs_registry_fops.write = entry->proc_fops->write;

    ..................

}


开始觉得很奇怪,这也不行的话,那C语言不就用不了了啊!

后来在网上搜到这个

http://forums.grsecurity.net/viewtopic.php?t=2716&p=11009

是PAX的错,里面给了一个补丁,主要就是在改写 nv_procfs_registry_fops的前后加了pax_open_kernel和pax_close_kernel。

补丁主要内容如下:


- nv_procfs_registry_fops.read = entry->proc_fops->read;

- nv_procfs_registry_fops.write = entry->proc_fops->write;

+ pax_open_kernel();

+ *(void **)&nv_procfs_registry_fops.read = entry->proc_fops->read;

+ *(void **)&nv_procfs_registry_fops.write = entry->proc_fops->write;

+ pax_close_kernel();


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值