Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in sgx_main.c - Assignment of Read-Only Member vm_flags on Branch 2.14 #160

Open
DylanCkawalec opened this issue May 24, 2024 · 2 comments

Comments

@DylanCkawalec
Copy link

Description

When attempting to build the Intel SGX driver on a system with kernel version 6.5.0-1021-azure, the following error occurs:

/home/username/linux-sgx-driver/sgx_main.c: In function ‘sgx_mmap’:
/home/username/linux-sgx-driver/sgx_main.c:112:23: error: assignment of read-only member ‘vm_flags’
  112 |         vma->vm_flags |= VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | VM_IO |
      |                       ^~
make[3]: *** [scripts/Makefile.build:251: /home/username/linux-sgx-driver/sgx_main.o] Error 1
make[2]: *** [/usr/src/linux-headers-6.5.0-1021-azure/Makefile:2039: /home/username/linux-sgx-driver] Error 2
make[1]: *** [Makefile:234: __sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.5.0-1021-azure'
make: *** [Makefile:16: default] Error 2

Cause

The error is caused by the code attempting to modify the vm_flags field of the vma structure directly, which is marked as read-only in recent kernel versions.

Solution

To resolve this issue, modify the sgx_main.c file to use an indirect method for modifying the vm_flags field. Here’s the corrected code snippet:

static int sgx_mmap(struct file *file, struct vm_area_struct *vma)
{
    vma->vm_ops = &sgx_vm_ops;
    unsigned long new_flags = vma->vm_flags | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | VM_IO | VM_DONTCOPY;
    *(unsigned long *)&vma->vm_flags = new_flags;
    return 0;
}

Steps to Reproduce

  1. Clone the Intel SGX driver repository.
  2. Attempt to build the driver using make on a system with kernel version 6.5.0-1021-azure.
  3. Observe the compilation error related to the vm_flags field in sgx_main.c.

Expected Behavior

The driver should compile without errors.

Environment

  • Kernel Version: 6.5.0-1021-azure
  • GCC Version: 11.4.0
  • Intel SGX Driver Version: 2.14.0

Additional Context

This issue and its solution were discussed and resolved during a development process. The fix involves using a safer approach to modify the read-only vm_flags field.

Jumpst3r added a commit to Jumpst3r/linux-sgx-driver that referenced this issue May 26, 2024
@GermanAizek
Copy link

Same error on master branch, commit bd80d04

@GermanAizek
Copy link

I found solution on Jumpst3r@215313b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants