Bug 6386 - `sysctl -a` tries to read write-only files (should skip them instead)
Summary: `sysctl -a` tries to read write-only files (should skip them instead)
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.21.x
Hardware: PC Linux
: P1 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-16 11:51 UTC by Gokul S
Modified: 2014-02-24 16:29 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments
Patch for the sysctl.c file to ignore the write only files in /proc/sys when the sysctl command is exeucted with "-a" option (549 bytes, patch)
2013-07-16 12:13 UTC, Gokul S
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gokul S 2013-07-16 11:51:43 UTC
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
Comment 1 Gokul S 2013-07-16 11:57:04 UTC
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"
Comment 2 Gokul S 2013-07-16 12:13:28 UTC
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
Comment 3 Gokul S 2013-07-16 12:27:45 UTC
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
Comment 4 Gokul S 2013-08-23 05:47:55 UTC
By applying this patch, sysctl will not read the write only files.
return value of the sysctl -a will be 0.
Comment 5 Denys Vlasenko 2014-02-24 16:29:42 UTC
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