procd jail incorrect mount behavior when openwrt is run in a container (namespaces)?

Đang mở
#22 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
c, linux
Lĩnh vực
operating-systems

Hướng nghiên cứu

Bắt đầu từ chuỗi mount của /sbin/ujail được thể hiện trong strace, đặc biệt là bind và remount chỉ-đọc của /dev/log, rồi so sánh với hành vi khóa flag của Linux mount namespace. Tái hiện dnsmasq jail bên trong một container và trace remount bị lỗi; được xem là hoàn thành khi jail xử lý các mount flag của container mà không gặp lỗi EPERM được báo cáo, đồng thời vẫn giữ các hạn chế dự kiến.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

see the following strace for dnsmasq

strace: Process 74923 attached                                                                                                                
[pid 74923] execve("/sbin/ujail", ["/sbin/ujail", "-t", "5", "-n", "dnsmasq", "-u", "-l", "-r", "/bin/ubus", "-r", "/etc/TZ", "-r", "/etc/dnsmasq.conf", "-r", "/etc/ethers", "-r", "/etc/group", "-r", "/etc/hosts", "-r", "/etc/passwd", "-w", "/tmp/dhcp.leases", "-r", "/tmp/dnsmasq.cfg01411c.d", "-r", "/tmp/hosts", "-r", "/tmp/resolv.conf.d", "-r", "/usr/bin/jshn", "-r", ...], 0x7fff4ddbc2f8 /* 10 vars */) = 0               
[pid 74923] clone(child_stack=0x5636ee84a718, flags=CLONE_NEWNS|CLONE_NEWIPC|CLONE_NEWPID|SIGCHLDstrace: Process 74924 attached) = 4367
[pid 74924] mount("none", "/", 0x5636ee7446dd, MS_REC|MS_PRIVATE, NULL) = 0                                                                   
[pid 74924] mount("tmpfs", "/tmp/ujail-EJimnB", "tmpfs", MS_NOATIME, "mode=0755") = 0                                                         
[pid 74924] mount("/bin/sh", "/tmp/ujail-EJimnB/bin/sh", 0x5636ee745e09, MS_BIND, NULL) = 0                                                   
[pid 74924] mount("/bin/sh", "/tmp/ujail-EJimnB/bin/sh", 0x5636ee7446dd, MS_RDONLY|MS_REMOUNT|MS_BIND, NULL) = 0                              
[pid 74924] mount("/bin/ubus", "/tmp/ujail-EJimnB/bin/ubus", 0x5636ee745e09, MS_BIND, NULL) = 0                                               
[pid 74924] mount("/bin/ubus", "/tmp/ujail-EJimnB/bin/ubus", 0x5636ee7446dd, MS_RDONLY|MS_REMOUNT|MS_BIND, NULL) = 0                          
[pid 74924] mount(NULL, "/tmp/ujail-EJimnB/dev", "tmpfs", MS_NOSUID|MS_NOEXEC|MS_NOATIME, "size=1M") = 0                                      
[pid 74924] mount("/dev/log", "/tmp/ujail-EJimnB/dev/log", 0x5636ee745e09, MS_BIND, NULL) = 0                                                 
[pid 74924] mount("/dev/log", "/tmp/ujail-EJimnB/dev/log", 0x5636ee7446dd, MS_REMOUNT|MS_BIND, NULL) = -1 EPERM (Operation not permitted)     
[pid 74924] +++ exited with 1 +++                                                                                                             
[pid 74923] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=4367, si_uid=0, si_status=1, si_utime=0, si_stime=0} ---                
[pid 74923] +++ exited with 1 +++                                                                                                             

in mount_namespaces - overview of Linux mount namespaces [5]. it is stated that

        The mount flags MS_RDONLY, MS_NOSUID, MS_NOEXEC, and the
        "atime" flags (MS_NOATIME, MS_NODIRATIME, MS_RELATIME)
        settings become locked when propagated from a more privileged
        to a less privileged mount namespace, and may not be changed
        in the less privileged mount namespace.

        This point is illustrated in the following example where, in
        a more privileged mount namespace, we create a bind mount
        that is marked as read-only.  For security reasons, it should
        not be possible to make the mount writable in a less
        privileged mount namespace, and indeed the kernel prevents
        this:

            $ sudo mkdir /mnt/dir
            $ sudo mount --bind -o ro /some/path /mnt/dir
            $ sudo unshare --user --map-root-user --mount \
                           mount -o remount,rw /mnt/dir
            mount: /mnt/dir: permission denied.

There's a workaround in lxc https://github.com/lxc/lxc-ci/issues/586 by unjailing dnsmasq. But I guess the proper way is to OR the original flags which may include nosuid?

bash-5.2# cat /proc/mounts | grep "/dev "                                                                    
tmpfs /dev tmpfs rw,nosuid,size=4096k,nr_inodes=65536,mode=755,uid=921370624,gid=921370624,inode64 0 0       
sysfs /sys/dev sysfs ro,nosuid,nodev,noexec,relatime 0 0                                                     

Note: ftrace seems to suggest EPERM from can_change_locked_flags()

Ngôn ngữ chính
C
Star
13
Fork
49
Merge trung bình
11 ngày 12 giờ
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của openwrt/procd

Tất cả issue của openwrt/procd

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.