How could I assign the owner of /proc/PID/maps? - linux

In my system, there is a user program (not a root program) running:
-r--r--r-- 1 root root 0 Mar 16 11:28 /proc/*****/maps
but another user process "vim" is:
-r--r--r-- 1 vagrant vagrant 0 Mar 16 11:28 /proc/*****/maps
I am wondering how could I control the owner of /proc/PID/maps of a binary? During compile time or during execution time?

Related

How to flash MB1355C and/or MB1293C from the STM32WB55 Nucleo Pack on Linux?

I would like to program the (MB1355C and/or MB1293C) devices from an STM32WB55 Nucleo Pack on my (Ubuntu 18.04.3 LTS) machine - preferably with the convenience of an eclipse based IDE that supports debugging features.
I installed
STM32CubeProgrammer (version 2.2.1)
Atolic TrueStudio (version 9.3.0)
STM32CubeIDE (version 1.1.0)
and I now have the following udev rules
chandran#chandran-OptiPlex-9020:~$ ll /etc/udev/rules.d/
total 160
drwxr-xr-x 2 root root 4096 Dec 13 14:11 ./
drwxr-xr-x 4 root root 4096 Dec 4 13:44 ../
-rw-rw-r-- 1 root root 270 Oct 14 18:10 49-stlinkv1.rules
-rw-rw-r-- 1 root root 270 Oct 14 18:10 49-stlinkv1.rules.O
-rw-rw-r-- 1 root root 464 Oct 14 18:10 49-stlinkv2-1.rules
-rw-rw-r-- 1 root root 464 Oct 14 18:10 49-stlinkv2-1.rules.O
-rw-rw-r-- 1 root root 278 Oct 14 18:10 49-stlinkv2.rules
-rw-rw-r-- 1 root root 278 Oct 14 18:10 49-stlinkv2.rules.O
-rw-r--r-- 1 root root 458 Dec 11 17:26 49-stlinkv3loader.rules
-rw-rw-r-- 1 root root 845 Oct 14 18:10 49-stlinkv3.rules
-rw-rw-r-- 1 root root 845 Oct 14 18:10 49-stlinkv3.rules.O
-rw-r--r-- 1 root root 381 Dec 6 17:10 '#61-msp430uif.rules#'
-rw-r--r-- 1 root root 381 Dec 4 15:09 61-msp430uif.rules
-rwxr-xr-x 1 root root 2145 Dec 4 15:09 70-mm-no-ti-emulators.rules*
-rw-r--r-- 1 root root 58549 Dec 4 12:29 70-snap.core.rules
-rw-r--r-- 1 root root 79 Dec 5 12:11 77-msp430-blacklist.rules
-rw-r--r-- 1 root root 0 Dec 5 12:10 77-msp430-blacklist.rules~
-rw-rw-r-- 1 root root 18450 Oct 14 17:33 99-jlink.rules
-rw-rw-r-- 1 root root 18450 Oct 14 17:33 99-jlink.rules.O
I am in the dialout group
chandran#chandran-OptiPlex-9020:~$ groups chandran
chandran : chandran adm dialout cdrom sudo dip plugdev lpadmin sambashare
I downloaded an example project called STM32100E-EVAL_USART_IrDA_Transmit and it builds successfully, but I get the following error message when I connect the evaluation board(s) and click on debug to flash the micro controller
ST-Link enumeration failed
Error in initializing ST-Link device.
Reason: (2) ST-Link DLL error.
I get the same error message when I try the above with STM32CubeIDE.
I have tried shifting JP1 as described in section 7.6 of the users manual but to no avail.
A previous question on stack overflow deals with the same error message so I got STM32CubeProgrammer to launch and tried making the changes suggested by #IsaBostan, but the development boards don't seem to be detected
How can I proceed to resolve this problem and program the boards?
Debugging ideas or suggestions are welcome, even if they haven't been tested...
It was just a question of permissions as suggested by KamilCuk
Launching TrueStudio as root and then clicking on debug solved the problem.
This is what worked on my machine:
sudo su
/opt/Atollic_TrueSTUDIO_for_STM32_x86_64_9.3.0/ide/./TrueSTUDIO
STM32CubeIDE's debugger also works when launched as follows on my machine:
sudo su
/opt/st/stm32cubeide_1.1.0/./stm32cubeide
and STM32CubeProgrammer connects to the device straight away when launched as follows:
sudo su
/usr/local/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/./STM32CubeProgrammer
My device shows up under /dev/ttyACM0 with the following permissions:
crw-rw----+ 1 root dialout 166, 0 Dec 28 11:56 ttyACM0
openocd and st-flash were not required.

Can't run dmidecode on docker container

I am trying to run command dmidecode in my docker container,
docker run --device /dev/mem:/dev/mem -it jin/ubu1604
However, it claims that there is no permission
root#bd1062dfd8ab:/# dmidecode
# dmidecode 3.0
Scanning /dev/mem for entry point.
/dev/mem: Operation not permitted
root#bd1062dfd8ab:/# ls -l /dev
total 0
crw--w---- 1 root tty 136, 0 Jan 7 03:21 console
lrwxrwxrwx 1 root root 11 Jan 7 03:20 core -> /proc/kcore
lrwxrwxrwx 1 root root 13 Jan 7 03:20 fd -> /proc/self/fd
crw-rw-rw- 1 root root 1, 7 Jan 7 03:20 full
crw-r----- 1 root kmem 1, 1 Jan 7 03:20 mem
drwxrwxrwt 2 root root 40 Jan 7 03:20 mqueue
crw-rw-rw- 1 root root 1, 3 Jan 7 03:20 null
lrwxrwxrwx 1 root root 8 Jan 7 03:20 ptmx -> pts/ptmx
drwxr-xr-x 2 root root 0 Jan 7 03:20 pts
crw-rw-rw- 1 root root 1, 8 Jan 7 03:20 random
drwxrwxrwt 2 root root 40 Jan 7 03:20 shm
lrwxrwxrwx 1 root root 15 Jan 7 03:20 stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root 15 Jan 7 03:20 stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root 15 Jan 7 03:20 stdout -> /proc/self/fd/1
crw-rw-rw- 1 root root 5, 0 Jan 7 03:20 tty
crw-rw-rw- 1 root root 1, 9 Jan 7 03:20 urandom
crw-rw-rw- 1 root root 1, 5 Jan 7 03:20 zero
This confused me. Since I was able to run dmidecode -t system on the host (ubuntu 14.04) fine.
I even followed some advice and set the permission on dmidecode executable
setcap cap_sys_rawio+ep /usr/sbin/dmidecode
It still doesn't work.
Any ideas?
UPDATE
Based on David Maze's answer, the command should be
run --device /dev/mem:/dev/mem --cap-add SYS_RAWIO -it my/ubu1604a
Do this only when you are going to trust what runs in container. For example, if you are test installation procedure on a pristine OS.
Docker provides an isolation layer, and one of the major goals of Docker is to hide details of the host's hardware from containers. The easiest, most appropriate way to query low-level details of the host's hardware is from a root shell on the host, ignoring Docker entirely.
The actual mechanism of this is by restricting Linux capabilities. capabilities(7) documents that you need CAP_SYS_RAWIO to access /dev/mem, so in principle you can launch your container with --cap-add SYS_RAWIO. You might need other capabilities and/or device access to make this actually work, because Docker is hiding the details of what you're trying to access as a design goal.

/dev/ttyACM0 File does not exist while Postfix pipe

When I run script as regular user manually, everything is OK. But if an email is received and piped into Go script, I can not open serial port because file does not exist.
postfix 1239 1025 0 13:20 ? 00:00:00 pipe -n watchParadox -t unix flags=F user=watch argv=/usr/local/bin/watch -paradox
watch 1240 1239 0 13:20 ? 00:00:00 /usr/local/bin/watch -paradox
Script is running under watch user who has been added to dialout group, postfix user, just to be sure, is in dialout also.
In my script I ran ls -la command to find out which files do truly exist:
drwxr-xr-x 6 root root 380 Feb 25 13:19 .
dr-xr-xr-x. 18 root root 4096 Feb 22 17:53 ..
lrwxrwxrwx 1 root root 11 Feb 25 13:19 core -> /proc/kcore
lrwxrwxrwx 1 root root 13 Feb 25 13:19 fd -> /proc/self/fd
crw-rw-rw- 1 root root 1, 7 Feb 25 13:19 full
drwxr-xr-x 2 root root 0 Feb 25 13:19 hugepages
lrwxrwxrwx 1 root root 28 Feb 25 13:19 log -> /run/systemd/journal/dev-log
drwxrwxrwt 2 root root 40 Feb 25 13:19 mqueue
crw-rw-rw- 1 root root 1, 3 Feb 25 13:19 null
lrwxrwxrwx 1 root root 8 Feb 25 13:19 ptmx -> pts/ptmx
drwxr-xr-x 2 root root 0 Feb 25 13:19 pts
crw-rw-rw- 1 root root 1, 8 Feb 25 13:19 random
drwxrwxrwt 2 root root 40 Feb 25 13:19 shm
lrwxrwxrwx 1 root root 15 Feb 25 13:19 stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root 15 Feb 25 13:19 stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root 15 Feb 25 13:19 stdout -> /proc/self/fd/1
crw-rw-rw- 1 root root 5, 0 Feb 25 13:19 tty
crw-rw-rw- 1 root root 1, 9 Feb 25 13:19 urandom
I am certain following file exists but is not shown when postfix pipe is executed.
crw-rw---- 1 root dialout 166, 0 25. úno 13.19 ttyACM0
I tried chmod 777 on the file but no luck in that department. Opening file via https://github.com/tarm/serial library which uses Go function:
os.OpenFile("ttyACM0", syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_NONBLOCK, 0666)
results with
ttyACM0: no such file or directory
The problem is not the path because I tried relative (using chdir) and absolute with same exact outcome.
I even disabled SELinux which is not what I want to do but in search of solution I try anything.
Code is OK because manual execution of the script passes through properly. I think there is something wrong with Linux settings.
The correct path the ttyACM0 is /dev/ttyACM0. You define a udev rules to set the file mode when it attaches.
If that is not reachable from your program, it might be the case that your program runs chrooted().
It seems like it was truly Linux problem and some underlying fabrics of it which I do not understand. I was running Fedora25 but the problem does not occur on Debian8.

Touch command. permission denied

I was able to connect to my school server via SSH. I had an assignment in which I was supposed to use the touch command to create a new file. Yet it keeps returning permission denied. Others were able to do the same thing. Though why do I keep getting this error?
Below is what was the input from the terminal.
Last login: Tue Aug 23 09:16:18 on ttys000
Dominiks-Air:~ fsociety95$ ssh djaneka1#navajo.dtcc.edu
djaneka1#navajo.dtcc.edu's password:
Last login: Tue Aug 23 09:16:35 2016 from pool-72-94-210-193.phlapa.fios.verizon.net
Navajo is Linux shell server provided to staff, faculty, and students. The
operating system is RedHat Enterprise Linux 5.
Alpine, a Pine replacement, has been provided as a mail client. Run "pine"
at the command prompt.
This server also provides web space to users. Web pages can be stored in
the ~/www directory. This is also accessible by mapping a drive in Windows
to \navajo\homepage. The URL for your homepage is
http://user.dtcc.edu/~username/.
Your home directory is also accessible in Windows by mapping to
\navajo\.
If something appears broken or missing, please email path#dtcc.edu.
Could not chdir to home directory /u/d/j/djaneka1: No such file or directory
-bash-3.2$ touch today
touch: cannot touch `today': Permission denied
-bash-3.2$ pwd
/
-bash-3.2$ touch today
touch: cannot touch `today': Permission denied
-bash-3.2$
Edit: here is the result of ls -al
-bash-3.2$ ls -al
total 204
drwxr-xr-x 25 root root 4096 Aug 22 16:50 .
drwxr-xr-x 25 root root 4096 Aug 22 16:50 ..
-rw-r--r-- 1 root root 0 Aug 3 14:01 .autofsck
-rw-r--r-- 1 root root 0 Jan 30 2009 .autorelabel
-rw------- 1 root root 2050 Aug 3 14:00 .bash_history
drwxr-xr-x 2 root root 4096 May 4 04:14 bin
drwxr-xr-x 4 root root 3072 Aug 3 13:57 boot
drwxr-xr-x 11 root root 4060 Aug 3 14:02 dev
drwxr-xr-x 87 root root 12288 Aug 23 10:05 etc
drwxr-xr-x 3 root root 4096 Oct 1 2009 home
drwxr-xr-x 13 root root 12288 Jun 1 04:09 lib
drwx------ 2 root root 16384 Mar 24 2008 lost+found
drwxr-xr-x 3 root root 4096 Oct 1 2009 media
drwxr-xr-x 2 root root 0 Aug 3 14:02 misc
drwxr-xr-x 4 root root 4096 May 26 2012 mnt
drwxr-xr-x 2 root root 0 Aug 3 14:02 net
drwxr-xr-x 9 root root 4096 Jan 5 2009 nsr
drwxrwxr-x 3 root root 4096 Oct 12 2015 opt
dr-xr-xr-x 219 root root 0 Aug 3 14:01 proc
drwxr-x--- 12 root root 4096 Apr 22 10:06 root
drwxr-xr-x 2 root root 12288 Aug 4 04:02 sbin
drwxr-xr-x 2 root root 4096 Oct 1 2009 selinux
drwxr-xr-x 2 root root 4096 Oct 1 2009 srv
drwxr-xr-x 11 root root 0 Aug 3 14:01 sys
drwxrwxrwt 38 root root 4096 Aug 23 10:07 tmp
drwxr-xr-x 34 root root 4096 Jun 21 08:29 u
drwxr-xr-x 14 root root 4096 Apr 16 2010 usr
drwxr-xr-x 24 root root 4096 Apr 16 2010 var
-rw------- 1 root root 2865 Dec 16 2008 .viminfo
-bash-3.2$
EDIT:
Here is what I see after trying touch today in /home
So to try and create a new document in the root directory you need to be recognised as root. That means using the sudo command.
However for that you would need a password that you may not have. If you do perfect. But in any case I would not recommend adding files to the root directory.
Instead try the following:
cd home
touch today
This should work just fine and answer your question.
Still if you need/want to create today in your root directory try the following
sudo touch today
You will then be prompted for the root password that you can type (if you have it obviously)
In any case I suggest reading this which may be very helpful for you.
I wonder if this was ever truly answered.
If I was looking at it, I would try to see what the system thinks is the home directory of djaneka1, since it may have been setup partway and not completed, leaving stuff owned by root that should have been owned by djaneka1.
If you use the pwd command, and get back the "/" (root) directory there is something wrong with your setup.
The message: Could not chdir to home directory /u/d/j/djaneka1: No such file or directory
tells you it can't find your home directory.
-bash-3.2$ pwd
/
the command "pwd" revealing "/" is just an artifact of the system not being able to find your home directory.
To find what the system thinks is one's home directory,
one can search the file named '/etc/passwd' for one's login name.
I expect this is a possible result if you do that:
$ fgrep 'djaneka1' /etc/passwd
djaneka1:x:1505:1506::/u/d/j/djaneka1:/bin/bash
since it complained that it couldn't find that directory.
This needs to be fixed by someone who has more rights to the system, like root.
there is nothing djaneka1 can do a

Size of kernel built is much much larger than the built-in one

I got latest kernel source from kernel.org(using git), and followed the steps as described in this page to build the kernel. The kernel boots successfully, however, I have no idea what was done incorrectly in the configuration process that initrd.img-3.16.0 is so much larger than the build in one(initrd.img-3.13.0-32-generic)
I copied the configuration file .config from /boot/ and used "yes '' | make oldconfig" for the kernel configuration.
the file size total 191M
-rw-r--r-- 1 root root 1.2M Jul 14 21:29 abi-3.13.0-32-generic
-rw-r--r-- 1 root root 162K Jul 14 21:29 config-3.13.0-32-generic
-rw-r--r-- 1 root root 167K Aug 4 19:48 config-3.16.0
-rw-r--r-- 1 root root 20M Jul 28 15:14 initrd.img-3.13.0-32-generic
-rw-r--r-- 1 root root 151M Aug 4 19:48 initrd.img-3.16.0
-rw-r--r-- 1 root root 173K Mar 12 05:31 memtest86+.bin
-rw-r--r-- 1 root root 174K Mar 12 05:31 memtest86+.elf
-rw-r--r-- 1 root root 175K Mar 12 05:31 memtest86+_multiboot.bin
-rw------- 1 root root 3.3M Jul 14 21:29 System.map-3.13.0-32-generic
-rw-r--r-- 1 root root 3.4M Aug 4 19:48 System.map-3.16.0
-rw------- 1 root root 5.6M Jul 14 21:29 vmlinuz-3.13.0-32-generic
-rw-r--r-- 1 root root 5.7M Aug 4 19:48 vmlinuz-3.16.0
Thanks!
William
follow below steps to obtain the right kernel configuration
Copy /boot/.config to the kernel source code directory
make menuconfig
Exit and save configuration
make
and then continue with the other options for install
Note : Since you are using make oldconfig, this would enable many of the options not related to the platform but related to the CPU architecture.
This steps should help you solve this issue

Resources