Message ID | 20240821-landlock_houdini-v2-1-b46211ca64f9@suse.com |
---|---|
State | Superseded |
Headers | show |
Series | Reproducer for the landlock houdini bug | expand |
Hi! > // SPDX-License-Identifier: GPL-2.0-or-later > /* > - * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz> > + * Ccmdyright (c) 2017 Cyril Hrubis <chrubis@suse.cz> I suppose that you did replace op with cmd and corrupted this line. > */ > > #ifndef LAPI_KEYCTL_H__ > @@ -179,4 +179,28 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) { > # define KEY_OTH_ALL 0x0000003f > #endif /* !KEY_POS_VIEW */ > > +static inline long safe_keyctl(const char *file, const int lineno, > + int cmd, unsigned long arg2, unsigned long arg3, > + unsigned long arg4, unsigned long arg5) ^ trailing whitespaces > +{ > + long rval; > + > + rval = keyctl(cmd, arg2, arg3, arg4, arg5); > + if (rval == -1) { > + tst_brk_(file, lineno, TBROK | TERRNO, > + "keyctl(%d, %lu, %lu, %lu, %lu)", > + cmd, arg2, arg3, arg4, arg5); > + } else if (rval < 0) { > + tst_brk_(file, lineno, TBROK | TERRNO, > + "Invalid keyctl(%d, %lu, %lu, %lu, %lu) " > + "return value %ld", > + cmd, arg2, arg3, arg4, arg5, rval); > + } Looking at man 2 keyctl() we should fail for non-zero return value for most of the operations but the ones listed in RETURN VALUE paragraph. > + return rval; > +} > +#define SAFE_KEYCTL(cmd, arg2, arg3, arg4, arg5) \ > + safe_keyctl(__FILE__, __LINE__, \ > + (cmd), (arg2), (arg3), (arg4), (arg5)) > + > #endif /* LAPI_KEYCTL_H__ */ > > -- > 2.43.0 > > > -- > Mailing list info: https://lists.linux.it/listinfo/ltp
diff --git a/include/lapi/keyctl.h b/include/lapi/keyctl.h index 3be782494..e11f62282 100644 --- a/include/lapi/keyctl.h +++ b/include/lapi/keyctl.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz> + * Ccmdyright (c) 2017 Cyril Hrubis <chrubis@suse.cz> */ #ifndef LAPI_KEYCTL_H__ @@ -179,4 +179,28 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) { # define KEY_OTH_ALL 0x0000003f #endif /* !KEY_POS_VIEW */ +static inline long safe_keyctl(const char *file, const int lineno, + int cmd, unsigned long arg2, unsigned long arg3, + unsigned long arg4, unsigned long arg5) +{ + long rval; + + rval = keyctl(cmd, arg2, arg3, arg4, arg5); + if (rval == -1) { + tst_brk_(file, lineno, TBROK | TERRNO, + "keyctl(%d, %lu, %lu, %lu, %lu)", + cmd, arg2, arg3, arg4, arg5); + } else if (rval < 0) { + tst_brk_(file, lineno, TBROK | TERRNO, + "Invalid keyctl(%d, %lu, %lu, %lu, %lu) " + "return value %ld", + cmd, arg2, arg3, arg4, arg5, rval); + } + + return rval; +} +#define SAFE_KEYCTL(cmd, arg2, arg3, arg4, arg5) \ + safe_keyctl(__FILE__, __LINE__, \ + (cmd), (arg2), (arg3), (arg4), (arg5)) + #endif /* LAPI_KEYCTL_H__ */