Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

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

@DylanCkawalec

Description

@DylanCkawalec

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions