From 01b9ee4c509e2882147af35eea4772d06ecd4150 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 7 Nov 2019 15:51:44 +0000 Subject: [PATCH] linux_renameat2: improve flag checks In the cases where Linux returns an error (e.g. passing in an undefined flag) there's no need for us to emit a message. (The target of this message is a developer working on the linuxulatorm, not the author of presumably broken Linux software). Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D21606 --- sys/compat/linux/linux_file.c | 7 +++++++ sys/compat/linux/linux_file.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c index 9451f26fd60..6e0e2b39e96 100644 --- a/sys/compat/linux/linux_file.c +++ b/sys/compat/linux/linux_file.c @@ -704,6 +704,13 @@ linux_renameat2(struct thread *td, struct linux_renameat2_args *args) int error, olddfd, newdfd; if (args->flags != 0) { + if (args->flags & ~(LINUX_RENAME_EXCHANGE | + LINUX_RENAME_NOREPLACE | LINUX_RENAME_WHITEOUT)) + return (EINVAL); + if (args->flags & LINUX_RENAME_EXCHANGE && + args->flags & (LINUX_RENAME_NOREPLACE | + LINUX_RENAME_WHITEOUT)) + return (EINVAL); linux_msg(td, "renameat2 unsupported flags 0x%x", args->flags); return (EINVAL); diff --git a/sys/compat/linux/linux_file.h b/sys/compat/linux/linux_file.h index 928be024de2..8742fa27b27 100644 --- a/sys/compat/linux/linux_file.h +++ b/sys/compat/linux/linux_file.h @@ -127,4 +127,11 @@ #define LINUX_F_UNLCK 2 #endif +/* + * renameat2 flags + */ +#define LINUX_RENAME_NOREPLACE 0x00000001 +#define LINUX_RENAME_EXCHANGE 0x00000002 +#define LINUX_RENAME_WHITEOUT 0x00000004 + #endif /* !_LINUX_FILE_H_ */