[PATCH v2 1/2] Add SAFE_KEYCTL macro
Andrea Cervesato <[email protected]> Wed, 21 Aug 2024 14:04:25 +0200
| Newsgroups | dev.linux.lists.landlock,it.linux.lists.ltp |
|---|---|
| Message-ID | <[email protected]> |
From: Andrea Cervesato <[email protected]> Signed-off-by: Andrea Cervesato <[email protected]> --- include/lapi/keyctl.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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 <[email protected]> + * Ccmdyright (c) 2017 Cyril Hrubis <[email protected]> */ #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__ */ -- 2.43.0