Skip to contentSkip to conversation

fs/sync.c : Add CAP_SYS_ADMIN checking before sync

PATCH In review Wuqixuan 3 participants 4 messages Apr 16, 2015 – Apr 21, 2015 VFS

lore
Share & tools
lore

Wuqixuan

author
#0 lore raw

PATCH 1/1 fs/sync.c : Add CAP_SYS_ADMIN checking before sync

The process, supposed in one container, can't flush the metadata and data of the all host's partitions without CAP_SYS_ADMIN capability, like sys_mount is doing. The checking will prevent some vicious programs impacting IO sequnces of those partitions, particularly, the ones which can't be accessed in the container.

---
fs/sync.c | 3 +++

1 file changed, 3 insertions(+)
fs/sync.c +0 -0
index fbc98ee..9f07909 100644
@@ -103,6 +103,9 @@ SYSCALL_DEFINE0(sync)

{
int nowait = 0, wait = 1;

+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
wakeup_flusher_threads(0, WB_REASON_SYNC);
iterate_supers(sync_inodes_one_sb, NULL);
iterate_supers(sync_fs_one_sb, &nowait);
--
1.9.1

#1 lore raw
Quoted 16 lines · Wuqixuan

The process, supposed in one container, can't flush the metadata and data of the all host's partitions without CAP_SYS_ADMIN capability, like sys_mount is doing. The checking will prevent some vicious programs impacting IO sequnces of those partitions, particularly, the ones which can't be accessed in the container.

---
fs/sync.c | 3 +++

1 file changed, 3 insertions(+)
fs/sync.c +0 -0
index fbc98ee..9f07909 100644

fs/sync.c SYSCALL_DEFINE0(sync) · line 107

Quoted 5 lines
fs/sync.c +2 -0
@@ -103,6 +103,9 @@ SYSCALL_DEFINE0(sync)
 {
 int nowait = 0, wait = 1;
 
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;

So after this patch I can't call sync as a regular user? (even without containers).
But nothing in sync(2) says about special permissions for this.

#2 lore raw
Quoted 20 lines · Azat Khuzhin
Quoted 19 lines · Wuqixuan

The process, supposed in one container, can't flush the metadata and data of the all host's partitions without CAP_SYS_ADMIN capability, like sys_mount is doing. The checking will prevent some vicious programs impacting IO sequnces of those partitions, particularly, the ones which can't be accessed in the container.

---
fs/sync.c | 3 +++

1 file changed, 3 insertions(+)
fs/sync.c +0 -0
index fbc98ee..9f07909 100644
@@ -103,6 +103,9 @@ SYSCALL_DEFINE0(sync)
 {
 int nowait = 0, wait = 1;
 
Quoted 6 lines

fs/sync.c SYSCALL_DEFINE0(sync) · line 107

Quoted 2 lines
fs/sync.c +2 -0
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;

So after this patch I can't call sync as a regular user? (even without containers).
But nothing in sync(2) says about special permissions for this.

Yeah, this solution will break userspace.
A much more generic solution would be to wait for cgroup aware writeback[1]. As temporary hack you can check whether the calling process is in the initial pid namesapce to detect
a container calling sync(2)...

[1] https://lwn.net/Articles/628631/

Signature · 2 lines
Thanks,
//richard
author
#3 lore raw

Thanks for your both replies. We will waiting for the patchset, and modify as per Richard's suggestion for temporary hack.

Quoted 34 lines · Richard Weinberger
Quoted 20 lines · Azat Khuzhin
Quoted 19 lines · Wuqixuan

The process, supposed in one container, can't flush the metadata and data of the all host's partitions without CAP_SYS_ADMIN capability, like sys_mount is doing. The checking will prevent some vicious programs impacting IO sequnces of those partitions, particularly, the ones which can't be accessed in the container.

---
fs/sync.c | 3 +++

1 file changed, 3 insertions(+)
fs/sync.c +0 -0
index fbc98ee..9f07909 100644
@@ -103,6 +103,9 @@ SYSCALL_DEFINE0(sync)
 {
 int nowait = 0, wait = 1;
 
Quoted 5 lines

fs/sync.c SYSCALL_DEFINE0(sync) · line 107

Quoted 2 lines
fs/sync.c +2 -0
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;

So after this patch I can't call sync as a regular user? (even without containers).
But nothing in sync(2) says about special permissions for this.

Yeah, this solution will break userspace.
A much more generic solution would be to wait for cgroup aware writeback[1]. As temporary hack you can check whether the calling process is in the initial pid namesapce to detect
a container calling sync(2)...

[1] https://lwn.net/Articles/628631/