Skip to content

Commit c84d079

Browse files
author
Dominik Brodowski
committed
ipc: add shmctl syscall/compat_syscall wrappers
Provide ksys_shmctl() and compat_ksys_shmctl() wrappers to avoid in-kernel calls to these syscalls. The ksys_ prefix denotes that these functions are meant as a drop-in replacement for the syscalls. In particular, they use the same calling convention as sys_shmctl() and compat_sys_shmctl(). This patch is part of a series which removes in-kernel calls to syscalls. On this basis, the syscall entry path can be streamlined. For details, see http://lkml.kernel.org/r/20180325162527.GA17492@light.dominikbrodowski.net Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
1 parent da1e274 commit c84d079

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎ipc/shm.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ static int shmctl_do_lock(struct ipc_namespace *ns, int shmid, int cmd)
10451045
return err;
10461046
}
10471047

1048-
SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)
1048+
long ksys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf)
10491049
{
10501050
int err, version;
10511051
struct ipc_namespace *ns;
@@ -1099,6 +1099,11 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)
10991099
}
11001100
}
11011101

1102+
SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)
1103+
{
1104+
return ksys_shmctl(shmid, cmd, buf);
1105+
}
1106+
11021107
#ifdef CONFIG_COMPAT
11031108

11041109
struct compat_shmid_ds {
@@ -1218,7 +1223,7 @@ static int copy_compat_shmid_from_user(struct shmid64_ds *out, void __user *buf,
12181223
}
12191224
}
12201225

1221-
COMPAT_SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, void __user *, uptr)
1226+
long compat_ksys_shmctl(int shmid, int cmd, void __user *uptr)
12221227
{
12231228
struct ipc_namespace *ns;
12241229
struct shmid64_ds sem64;
@@ -1273,6 +1278,11 @@ COMPAT_SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, void __user *, uptr)
12731278
}
12741279
return err;
12751280
}
1281+
1282+
COMPAT_SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, void __user *, uptr)
1283+
{
1284+
return compat_ksys_shmctl(shmid, cmd, uptr);
1285+
}
12761286
#endif
12771287

12781288
/*

‎ipc/syscall.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
9494
case SHMGET:
9595
return ksys_shmget(first, second, third);
9696
case SHMCTL:
97-
return sys_shmctl(first, second,
97+
return ksys_shmctl(first, second,
9898
(struct shmid_ds __user *) ptr);
9999
default:
100100
return -ENOSYS;
@@ -182,7 +182,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
182182
case SHMGET:
183183
return ksys_shmget(first, (unsigned int)second, third);
184184
case SHMCTL:
185-
return compat_sys_shmctl(first, second, compat_ptr(ptr));
185+
return compat_ksys_shmctl(first, second, compat_ptr(ptr));
186186
}
187187

188188
return -ENOSYS;

‎ipc/util.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,15 @@ long ksys_semctl(int semid, int semnum, int cmd, unsigned long arg);
245245
long ksys_msgget(key_t key, int msgflg);
246246
long ksys_shmget(key_t key, size_t size, int shmflg);
247247
long ksys_shmdt(char __user *shmaddr);
248+
long ksys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf);
248249

249250
/* for CONFIG_ARCH_WANT_OLD_COMPAT_IPC */
250251
#ifdef CONFIG_COMPAT
251252
long compat_ksys_semtimedop(int semid, struct sembuf __user *tsems,
252253
unsigned int nsops,
253254
const struct compat_timespec __user *timeout);
254255
long compat_ksys_semctl(int semid, int semnum, int cmd, int arg);
256+
long compat_ksys_shmctl(int shmid, int cmd, void __user *uptr);
255257
#endif /* CONFIG_COMPAT */
256258

257259
#endif

0 commit comments

Comments
 (0)