Announcement

Collapse
No announcement yet.

/dev/mem and even /dev/port can't open even as root!

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [RESOLVED] /dev/mem and even /dev/port can't open even as root!



    I made a program that tries to do mmaping on /dev/mem and it fails with:
    Failed to open /dev/mem: Operation not permitted



    And I tried using od as a test for my code being bad too:
    od: /dev/mem: Operation not permitted

    od: /dev/port: Operation not permitted
    How do I make these files open-able?

    #2
    Welcome!

    You could read those with elevated privileges as you can see with ls -lh /dev/ .

    What did you try to do and how did you try it - exactly?
    Last edited by Schwarzer Kater; May 08, 2023, 08:04 PM.
    Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
    Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

    get rid of Snap script (20.04 +)reinstall Snap for release-upgrade script (20.04 +)
    install traditional Firefox script (22.04 +)​ • install traditional Thunderbird script (24.04)

    Comment


      #3
      Write to memory-mapped vga controller using a C program I made

      Comment


        #4
        FWIW,
        Code:
        sudo od /dev/mem | more
        sudo od /dev/port | more
        have no trouble for me.
        Regards, John Little

        Comment


          #5
          And neither does my VM running the same version of Kubuntu as the host, Well technically the /dev/mem fails with the same error but it's after it has read at least some data.

          Comment


            #6
            There's no point of /dev/mem or /dev/port if you can't open them

            Comment


              #7
              To cite from https://bakhi.github.io/devmem/ :

              " To use /dev/mem, your kernel must be configured with “CONFIG_STRICT_DEVMEM=n”, or it prevent access from even privileged user.

              “CONFIG_STRICT_DEVMEM=y”, the default kernel configuration in general, disallows to access RAM area via /dev/mem or only allows first 1MB size of RAM

              FYI: “CONFIG_IO_STRICT_DEVMEM=y”, disallows to access register via dev/mem​
              "


              This seems to be a safety precaution and as far as I have read on other internet sites CONFIG_STRICT_DEVMEM has to be configured before kernel compilation…
              Last edited by Schwarzer Kater; May 09, 2023, 03:17 PM.
              Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
              Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

              get rid of Snap script (20.04 +)reinstall Snap for release-upgrade script (20.04 +)
              install traditional Firefox script (22.04 +)​ • install traditional Thunderbird script (24.04)

              Comment


                #8
                I thought it limited reads and writes to 1 MiB, not disabling them and my VM shows that is true and that dosen't even apply to mmaped memory and CONFIG_STRICT_DEVMEM as a fact dosen't affect /dev/port.

                Comment


                  #9
                  This seems to be specific to my machine, my VM has no problems with this.

                  Comment


                    #10
                    Do you (Joe) have any PPAs that may have installed a kernel? What does uname -rv say?
                    Code:
                    $ uname -rv
                    5.15.0-71-generic #78-Ubuntu SMP Tue Apr 18 09:00:29 UTC 2023​
                    Regards, John Little

                    Comment


                      #11
                      Here is the output:
                      5.15.0-71-generic #78-Ubuntu SMP Tue Apr 18 09:00:29 UTC 2023
                      And no PPAs that could have installed a new kernel that I know of.
                      Last edited by TheRandomGuyNamedJoe12; May 09, 2023, 08:53 PM.

                      Comment


                        #12
                        Originally posted by TheRandomGuyNamedJoe12 View Post
                        […] and CONFIG_STRICT_DEVMEM as a fact dosen't affect /dev/port.
                        I did not claim that.


                        Kubuntu 22.04:
                        Code:
                        uname -rv
                        5.19.0-41-generic #42~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 18 17:40:00 UTC 2​

                        My (partial) output of LC_ALL=C sudo od /dev/port in Kubuntu 22.04:
                        Code:
                        …
                        0170120 000020 134317 010540 000403 010421 000021 000000 000000
                        …​

                        and no error at all.


                        My output of LC_ALL=C sudo od /dev/mem | echo $((($(wc -l)-2)/8)) in Kubuntu 22.04:
                        Code:
                        od: /dev/mem: Operation not permitted
                        1024​
                        = 1 MiB limitation.


                        Similar outputs of od in Debian and openSUSE.
                        And in your Kubuntus you get the error message only from reading /dev/port and /dev/mem and no other output at all?​
                        Last edited by Schwarzer Kater; May 10, 2023, 05:33 AM.
                        Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
                        Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

                        get rid of Snap script (20.04 +)reinstall Snap for release-upgrade script (20.04 +)
                        install traditional Firefox script (22.04 +)​ • install traditional Thunderbird script (24.04)

                        Comment


                          #13
                          My point is that opening is supposed to be allowed.
                          Last edited by TheRandomGuyNamedJoe12; May 10, 2023, 09:21 AM.

                          Comment


                            #14
                            My output of
                            Code:
                            LC_ALL=C sudo od /dev/mem | echo $((($(wc -l)-2)/8))
                            Code:
                            od: /dev/mem: Operation not permitted
                            0

                            Comment


                              #15
                              It is a security update, marking as wontfix.

                              Comment

                              Working...
                              X