最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Kernel Module - Character Device and Sysfs Permissions Issue - Stack Overflow

programmeradmin3浏览0评论

I am developing a kernel module that, during initialization, creates a character device and multiple sysfs entries. I need to allow user-space access (non-root, non-sudo) to both. I want to be able to set permissions on each of the files separately.

I am running on a Pixel 8 device (Shiba) with kernel version 5.15.137-android14-11-gbc062a78e195-ab12057991.

What I did:

Character Device Issue:

  1. Using devnode in class_create

I attempted the following approaches but had no success: First I executed the following,

new_class = class_create(THIS_MODULE, DEVICE_CLASS_NAME);
new_class->devnode = custom_devnode;

where,

static char *custom_devnode(struct device *dev, umode_t *mode) {
    if (mode) *mode = (S_IRUGO | S_IWUGO);
    return NULL;
}

However, this had no effect on the character device permissions:

0 crw------- 1 root root 486,   0 2024-11-18 19:15 /dev/my_char_device
  1. Using dev_uevent (Based on StackOverflow Suggestion: Linux Kernel Module Character Device Permissions) First I executed the following,
new_class = class_create(THIS_MODULE, DEVICE_CLASS_NAME);
new_class->dev_uevent = custom_dev_uevent;

where,

static int custom_dev_uevent(struct device *dev, struct kobj_uevent_env *env) {
    add_uevent_var(env, "DEVMODE=%#o", 0660);
    return 0;
}

Again, this had no effect on the character device permissions (identical output to before).

Sysfs Permissions Issue:

I defined sysfs attributes using the __ATTR macro and explicitly set 0666 permissions where necessary. While the sysfs files are created with the correct permissions, non-root users still receive "Permission Denied" when attempting access.

I would note that I failed to set the permissions even manually using cli. Notice that I am rnning on an Android phone, so maybe it is somehow related?

I would appreciate any insights or suggestions to resolve this issue.

Thanks!

发布评论

评论列表(0)

  1. 暂无评论