Scenario : On the execution of the sysctl command with "-a" option in a normal suse machine, showing some messages like "sysctl: error reading key 'net.ipv6.route.flush': Permission denied" "sysctl: error reading key 'net.ipv4.route.flush': Permission denied" And , return value of the command execution is 1
Analysis : Sysctl -a option will Display all values currently available (all values inside /proc/sys/) net.ipv4.route.flush entry ( /proc/sys/net/ipv4/route/flush ) corresponds to a write only file , used to flush the route information. root@SMM:~# ls -l /proc/sys/net/ipv4/route/flush --w------- 1 root root 0 Jun 14 17:38 /proc/sys/net/ipv4/route/flush sysctl -a option trying to read the /proc/sys/net/ipv4/route/flush file. As it is write only, it is throwing following message. "sysctl: error reading key 'net.ipv6.route.flush': Permission denied"
Created attachment 4988 [details] Patch for the sysctl.c file to ignore the write only files in /proc/sys when the sysctl command is exeucted with "-a" option
Proposed Fix: If the file does not have the following permissions , then the file will be ignored. S_IRUSR - read permission, Owner S_IRGRP - read permission, Group S_IROTH - read permission, Others Here , in the patch code, if the file does not have the above three permission, then it will enter into the "if" condition. It will return as "EXIT_SUCCESS" So, the sysctl command execution with "-a" option will not read write only files and the return value of the command execution will be "zero" Note: ----- This issue is not present in procps-3.2.7-151.8.31 A patch is added to resolve this issue : procps-3.2.7-sysctl-writeonly.patch https://github.com/pisilinux/PisiLinux/blob/master/system/base/procps/files/procps-3.2.7-sysctl-writeonly.patch
By applying this patch, sysctl will not read the write only files. return value of the sysctl -a will be 0.
Fixed in git: commit 6554d03735e394c613ebacfe6b8d7b239e164310 Author: Denys Vlasenko <vda.linux@googlemail.com> Date: Mon Feb 24 17:28:43 2014 +0100 sysctl: do not error out showing write-only data. Closes 6386