Skip to content

Commit e38b36f

Browse files
Ulrich Dreppertorvalds
authored andcommitted
flag parameters: check magic constants
This patch adds test that ensure the boundary conditions for the various constants introduced in the previous patches is met. No code is generated. [akpm@linux-foundation.org: fix alpha] Signed-off-by: Ulrich Drepper <drepper@redhat.com> Acked-by: Davide Libenzi <davidel@xmailserver.org> Cc: Michael Kerrisk <mtk.manpages@googlemail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 510df2d commit e38b36f

File tree

6 files changed

+25
-0
lines changed

6 files changed

+25
-0
lines changed

fs/eventfd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ asmlinkage long sys_eventfd2(unsigned int count, int flags)
203203
int fd;
204204
struct eventfd_ctx *ctx;
205205

206+
/* Check the EFD_* constants for consistency. */
207+
BUILD_BUG_ON(EFD_CLOEXEC != O_CLOEXEC);
208+
BUILD_BUG_ON(EFD_NONBLOCK != O_NONBLOCK);
209+
206210
if (flags & ~(EFD_CLOEXEC | EFD_NONBLOCK))
207211
return -EINVAL;
208212

fs/eventpoll.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,9 @@ asmlinkage long sys_epoll_create2(int size, int flags)
10511051
int error, fd = -1;
10521052
struct eventpoll *ep;
10531053

1054+
/* Check the EPOLL_* constant for consistency. */
1055+
BUILD_BUG_ON(EPOLL_CLOEXEC != O_CLOEXEC);
1056+
10541057
if (flags & ~EPOLL_CLOEXEC)
10551058
return -EINVAL;
10561059

fs/inotify_user.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,10 @@ asmlinkage long sys_inotify_init1(int flags)
574574
struct file *filp;
575575
int fd, ret;
576576

577+
/* Check the IN_* constants for consistency. */
578+
BUILD_BUG_ON(IN_CLOEXEC != O_CLOEXEC);
579+
BUILD_BUG_ON(IN_NONBLOCK != O_NONBLOCK);
580+
577581
if (flags & ~(IN_CLOEXEC | IN_NONBLOCK))
578582
return -EINVAL;
579583

fs/signalfd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ asmlinkage long sys_signalfd4(int ufd, sigset_t __user *user_mask,
211211
sigset_t sigmask;
212212
struct signalfd_ctx *ctx;
213213

214+
/* Check the SFD_* constants for consistency. */
215+
BUILD_BUG_ON(SFD_CLOEXEC != O_CLOEXEC);
216+
BUILD_BUG_ON(SFD_NONBLOCK != O_NONBLOCK);
217+
214218
if (flags & ~(SFD_CLOEXEC | SFD_NONBLOCK))
215219
return -EINVAL;
216220

fs/timerfd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ asmlinkage long sys_timerfd_create(int clockid, int flags)
184184
int ufd;
185185
struct timerfd_ctx *ctx;
186186

187+
/* Check the TFD_* constants for consistency. */
188+
BUILD_BUG_ON(TFD_CLOEXEC != O_CLOEXEC);
189+
BUILD_BUG_ON(TFD_NONBLOCK != O_NONBLOCK);
190+
187191
if (flags & ~(TFD_CLOEXEC | TFD_NONBLOCK))
188192
return -EINVAL;
189193
if (clockid != CLOCK_MONOTONIC &&

net/socket.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,12 @@ asmlinkage long sys_socket(int family, int type, int protocol)
12221222
struct socket *sock;
12231223
int flags;
12241224

1225+
/* Check the SOCK_* constants for consistency. */
1226+
BUILD_BUG_ON(SOCK_CLOEXEC != O_CLOEXEC);
1227+
BUILD_BUG_ON((SOCK_MAX | SOCK_TYPE_MASK) != SOCK_TYPE_MASK);
1228+
BUILD_BUG_ON(SOCK_CLOEXEC & SOCK_TYPE_MASK);
1229+
BUILD_BUG_ON(SOCK_NONBLOCK & SOCK_TYPE_MASK);
1230+
12251231
flags = type & ~SOCK_TYPE_MASK;
12261232
if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
12271233
return -EINVAL;

0 commit comments

Comments
 (0)