* [PATCH iproute2] lib/namespace: don't try to mount rw /sys over a ro one
@ 2018-02-12 19:23 Lubomir Rintel
2018-02-13 10:55 ` Phil Sutter
2018-02-23 16:08 ` Stephen Hemminger
0 siblings, 2 replies; 3+ messages in thread
From: Lubomir Rintel @ 2018-02-12 19:23 UTC (permalink / raw)
To: netdev; +Cc: Phil Sutter, Lubomir Rintel
It will fail with EPERM on Linux 4.15.
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
lib/namespace.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/lib/namespace.c b/lib/namespace.c
index 30b51388..6f3356d0 100644
--- a/lib/namespace.c
+++ b/lib/namespace.c
@@ -7,6 +7,7 @@
* 2 of the License, or (at your option) any later version.
*/
+#include <sys/statvfs.h>
#include <fcntl.h>
#include <dirent.h>
#include <limits.h>
@@ -46,6 +47,8 @@ int netns_switch(char *name)
{
char net_path[PATH_MAX];
int netns;
+ unsigned long mountflags = 0;
+ struct statvfs fsstat;
snprintf(net_path, sizeof(net_path), "%s/%s", NETNS_RUN_DIR, name);
netns = open(net_path, O_RDONLY | O_CLOEXEC);
@@ -73,12 +76,25 @@ int netns_switch(char *name)
strerror(errno));
return -1;
}
+
/* Mount a version of /sys that describes the network namespace */
- if (umount2("/sys", MNT_DETACH) < 0) {
- fprintf(stderr, "umount of /sys failed: %s\n", strerror(errno));
+
+ if (statvfs("/sys", &fsstat) < 0) {
+ fprintf(stderr, "could not stat /sys (not mounted?): %s\n",strerror(errno));
return -1;
}
- if (mount(name, "/sys", "sysfs", 0, NULL) < 0) {
+ if (fsstat.f_flag & ST_RDONLY) {
+ /* If /sys is not writable (e.g. in a container), we can't
+ * unmount the old /sys instance, but we can still mount a new
+ * read-only instance over it. */
+ mountflags = MS_RDONLY;
+ } else {
+ if (umount2("/sys", MNT_DETACH) < 0) {
+ fprintf(stderr, "umount of /sys failed: %s\n", strerror(errno));
+ return -1;
+ }
+ }
+ if (mount(name, "/sys", "sysfs", mountflags, NULL) < 0) {
fprintf(stderr, "mount of /sys failed: %s\n",strerror(errno));
return -1;
}
--
2.14.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2] lib/namespace: don't try to mount rw /sys over a ro one
2018-02-12 19:23 [PATCH iproute2] lib/namespace: don't try to mount rw /sys over a ro one Lubomir Rintel
@ 2018-02-13 10:55 ` Phil Sutter
2018-02-23 16:08 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Phil Sutter @ 2018-02-13 10:55 UTC (permalink / raw)
To: Lubomir Rintel; +Cc: netdev
On Mon, Feb 12, 2018 at 08:23:12PM +0100, Lubomir Rintel wrote:
> It will fail with EPERM on Linux 4.15.
>
> Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Acked-by: Phil Sutter <phil@nwl.cc>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2] lib/namespace: don't try to mount rw /sys over a ro one
2018-02-12 19:23 [PATCH iproute2] lib/namespace: don't try to mount rw /sys over a ro one Lubomir Rintel
2018-02-13 10:55 ` Phil Sutter
@ 2018-02-23 16:08 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2018-02-23 16:08 UTC (permalink / raw)
To: Lubomir Rintel; +Cc: netdev, Phil Sutter
On Mon, 12 Feb 2018 20:23:12 +0100
Lubomir Rintel <lkundrak@v3.sk> wrote:
> It will fail with EPERM on Linux 4.15.
>
> Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-02-23 16:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-12 19:23 [PATCH iproute2] lib/namespace: don't try to mount rw /sys over a ro one Lubomir Rintel
2018-02-13 10:55 ` Phil Sutter
2018-02-23 16:08 ` Stephen Hemminger
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.