It possibly is a security vulnerability. That's why there's for example the Linux security module Yama, that restricts ptrace and thereby access to /proc/<pid>/mem
.
As Linux grows in popularity, it will become a larger target for
malware. One particularly troubling weakness of the Linux process
interfaces is that a single user is able to examine the memory and
running state of any of their processes. For example, if one application
(e.g. Pidgin) was compromised, it would be possible for an attacker to
attach to other running processes (e.g. Firefox, SSH sessions, GPG agent,
etc) to extract additional credentials and continue to expand the scope
of their attack without resorting to user-assisted phishing.
This is not a theoretical problem. SSH session hijacking
(http://www.storm.net.nz/projects/7) and arbitrary code injection
(http://c-skills.blogspot.com/2007/05/injectso.html) attacks already
exist and remain possible if ptrace is allowed to operate as before.
Since ptrace is not commonly used by non-developers and non-admins, system
builders should be allowed the option to disable this debugging system.
source: Kernel documentation on Yama
I can't reproduce your experiment on Linux kernel 5.4.0, i.e. I get a Permission denied error:
$ echo '<addr>' | xxd -p -r | dd of=/proc/<pid>/mem bs=1 seek=$((ADDR)) count=4 conv=notrunc
dd: failed to open '/proc/<pid>/mem': Permission denied
The behavior depends on your system's configuration. For example if the Linux security module Yama is active and ptrace_scope
is set to mode 1, by default, a process can only read it's own or its childrens' mem-files.
1 - restricted ptrace: a process must have a predefined relationship
with the inferior it wants to call PTRACE_ATTACH on. By default,
this relationship is that of only its descendants when the above
classic criteria is also met. To change the relationship, an
inferior can call prctl(PR_SET_PTRACER, debugger, ...) to declare
an allowed debugger PID to call PTRACE_ATTACH on the inferior.
Using PTRACE_TRACEME is unchanged.
(ibid)
/proc/pid/mem
This file can be used to access the pages of a process's
memory through open(2), read(2), and lseek(2).
Permission to access this file is governed by a ptrace
access mode PTRACE_MODE_ATTACH_FSCREDS check; see
ptrace(2).
man 5 proc
PTRACE_MODE_ATTACH_FSCREDS
Defined as PTRACE_MODE_ATTACH | PTRACE_MODE_FSCREDS.
man 2 ptrace
More details on the access checks can be found in this CloudFlare blog post on "Diving into /proc/[pid]/mem".
/proc/<pid>/mem
for processes that are running as your UID. I'm not sure that's any more of a security vulnerability than the fact that any program you run can create/delete/rename/modify any files that you own.