2017-02-17 149 views
0

我在嘗試運行一段非常簡單的代碼時遇到了一些麻煩,無法找出原因。試圖從.ko文件(KO_NAME)安裝一個Linux內核模塊時爲什麼在嘗試安裝Linux內核模塊時會「不允許操作」?

我越來越

操作不允許

這是代碼的摘錄:

if (strcmp(argv[1], "-init")==0) { 

    fd=open(KO_NAME, O_RDONLY|O_CLOEXEC); 
    if (fd<0) { 
     perror("Error"); 
     printf("Error number: %d\n", errno); 
    } else { 
     printf("fd: %d\n", fd); 
    } 
    uid=getuid(); 
    if (uid!=ROOT_UID) { 
     printf("Error: not root\n"); 
     return -1; 
    } 
    if (access(KO_NAME, F_OK)==-1) { 
     printf("Error: File \"%s\" doesn't exist\n", argv[2]); 
     return -1; 
    } 
    rc=syscall(__NR_finit_module, fd, "", 0); 
     close(fd); 
     if (rc!=0) { 
      perror("Error"); 
      printf("rc=%d\n", rc); 
      printf("Error number: %d\n", errno); 
     } 

,這是結果運行時:

fd: 3 

rc=-1 

Error number: 1 

爲什麼會出現錯誤number 1

操作不允許

+3

您是否試過'/ sbin/insmod '?這可能是因爲modue文件不適合你的內核。 – Tsyvarev

+1

僅供參考:該系統調用有'finit_module()'封裝,請參閱[man init_module](http://man7.org/linux/man-pages/man2/init_module.2.html)。 –

回答

1

我 「不允許操作」 安裝Linux內核太錯誤。我正在運行Sophos Anti-Virus,它有一個已知的錯誤。 "30s delay of file create and "Operation not permitted" errors with fanotify and cifs – This is a kernel issue and Sophos is working with the Linux community to fix this issue"

爲了解決這個問題,我先禁用了sophos-av,然後在每次安裝Linux內核後啓用它。在Linux內核安裝期間,我只遇到過這個問題,而不是在常見的更新過程中。

sudo /opt/sophos-av/bin/savdctl disable

運行Update Manager和安裝Linux內核。

sudo /opt/sophos-av/bin/savdctl enable

0

內核模塊可以僅由通過默認根用戶訪問。 因此,在insmod之後,您必須使用root用戶打開設備文件。

因此,您必須使用sudo來打開文件。

相關問題