From patchwork Thu Mar 1 13:48:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yang xu X-Patchwork-Id: 880290 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zswcx5spxz9sW3 for ; Fri, 2 Mar 2018 15:02:55 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 52E5F3E7337 for ; Fri, 2 Mar 2018 05:02:52 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id E798F3E72AF for ; Fri, 2 Mar 2018 05:02:49 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id B9E601A01789 for ; Fri, 2 Mar 2018 05:02:45 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="37410170" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 02 Mar 2018 12:02:41 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 34A5F48AE761 for ; Fri, 2 Mar 2018 12:02:37 +0800 (CST) Received: from localhost.localdomain (10.167.220.59) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 2 Mar 2018 12:02:36 +0800 From: Yang Xu To: Date: Thu, 1 Mar 2018 21:48:58 +0800 Message-ID: <1519912139-18839-1-git-send-email-xuyang.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.7.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.59] X-yoursite-MailScanner-ID: 34A5F48AE761.AD7BC X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang.jy@cn.fujitsu.com X-Spam-Status: No, score=0.8 required=7.0 tests=DATE_IN_PAST_12_24, T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 1/2] utils/compat_16: Add compat_tst_16.h for new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: yang xu 1) Make sure compat_16.mk can be used by both new API and old API 2) Remove unused TST_COMPAT_16_SYSCALL judgment in compat_16.mk Signed-off-by: yang xu --- testcases/kernel/syscalls/utils/compat_16.mk | 11 +- testcases/kernel/syscalls/utils/compat_tst_16.h | 157 ++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 testcases/kernel/syscalls/utils/compat_tst_16.h diff --git a/testcases/kernel/syscalls/utils/compat_16.mk b/testcases/kernel/syscalls/utils/compat_16.mk index 3378908..0565dde 100644 --- a/testcases/kernel/syscalls/utils/compat_16.mk +++ b/testcases/kernel/syscalls/utils/compat_16.mk @@ -12,9 +12,7 @@ # the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# +# along with this program. If not, see . # Author: Masatake YAMATO # Technique used here is suggested by Ngie Cooper @@ -56,16 +54,17 @@ SRCS ?= $(wildcard $(abs_srcdir)/*.c) MAKE_TARGETS := $(notdir $(patsubst %.c,%,$(SRCS))) MAKE_TARGETS_OBJS_WO_COMPAT_16 := $(addsuffix .o,$(MAKE_TARGETS)) - -ifneq ($(TST_COMPAT_16_SYSCALL),no) MAKE_TARGETS += $(addsuffix _16,$(MAKE_TARGETS)) -endif # XXX (garrcoop): This code should be put in question as it cannot be applied # (no .h file, no TST_USE_NEWER64_SYSCALL def). DEF_16 := TST_USE_COMPAT16_SYSCALL +ifneq ($(COMPAT_TST_16_H),1) COMPAT_16_H := $(abs_srcdir)/../utils/compat_16.h +else +COMPAT_16_H := $(abs_srcdir)/../utils/compat_tst_16.h +endif ifneq ($(wildcard $(COMPAT_16_H)),) HAS_COMPAT_16 := 1 diff --git a/testcases/kernel/syscalls/utils/compat_tst_16.h b/testcases/kernel/syscalls/utils/compat_tst_16.h new file mode 100644 index 0000000..bb30c6f --- /dev/null +++ b/testcases/kernel/syscalls/utils/compat_tst_16.h @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. + * Author: yang xu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __LTP_COMPAT_TST_16_H__ +#define __LTP_COMPAT_TST_16_H__ + +#include +#include +#if defined(__GLIBC__) || defined(__ANDROID__) +#include +#endif +#include +#include + +#include "compat_gid.h" +#include "compat_uid.h" +#include "lapi/syscalls.h" + +int setresuid(uid_t ruid, uid_t euid, uid_t suid); +int setresgid(gid_t rgid, gid_t egid, gid_t sgid); + + +/* If the platform has __NR_sys_name32 defined it + * means that __NR_sys_name is a 16-bit version of + * sys_name() syscall + */ +#ifdef TST_USE_COMPAT16_SYSCALL +# define TST_CREATE_SYSCALL(sys_name, ...) ({ \ + if (__NR_##sys_name##32 != __LTP__NR_INVALID_SYSCALL) { \ + return tst_syscall(__NR_##sys_name, ##__VA_ARGS__); \ + } else { \ + tst_brk(TCONF, \ + "16-bit version of %s() is not supported on your " \ + "platform", #sys_name); \ + return -1; \ + } \ +}) +#else +# define TST_CREATE_SYSCALL(sys_name, ...) ({\ + return sys_name(__VA_ARGS__); \ +}) +#endif + +#define UID16_CHECK(uid, sys_name) ({ \ + if (!UID_SIZE_CHECK(uid)) { \ + tst_brk(TBROK, \ + "uid %d of %s is too large for testing 16-bit " \ + "version of %s()", uid, #uid, #sys_name); \ + } \ +}) +#define GID16_CHECK(gid, sys_name) ({ \ + if (!GID_SIZE_CHECK(gid)) { \ + tst_brk(TBROK, \ + "gid %d of %s is too large for testing 16-bit " \ + "version of %s()", gid, #gid, #sys_name); \ + } \ +}) + +int SETGROUPS(size_t gidsetsize, GID_T *list) +{ + TST_CREATE_SYSCALL(setgroups, gidsetsize, list); +} + +int GETGROUPS(size_t gidsetsize, GID_T *list) +{ + TST_CREATE_SYSCALL(getgroups, gidsetsize, list); +} + +int SETUID(UID_T uid) +{ + TST_CREATE_SYSCALL(setuid, uid); +} + +UID_T GETUID(void) +{ + TST_CREATE_SYSCALL(getuid); +} + +int SETGID(GID_T gid) +{ + TST_CREATE_SYSCALL(setgid, gid); +} + +GID_T GETGID(void) +{ + TST_CREATE_SYSCALL(getgid); +} + +UID_T GETEUID(void) +{ + TST_CREATE_SYSCALL(geteuid); +} + +GID_T GETEGID(void) +{ + TST_CREATE_SYSCALL(getegid); +} + +int SETFSUID(UID_T uid) +{ + TST_CREATE_SYSCALL(setfsuid, uid); +} + +int SETFSGID(GID_T gid) +{ + TST_CREATE_SYSCALL(setfsgid, gid); +} + +int SETREUID(UID_T ruid, UID_T euid) +{ + TST_CREATE_SYSCALL(setreuid, ruid, euid); +} +int SETREGID(GID_T rgid, GID_T egid) +{ + TST_CREATE_SYSCALL(setregid, rgid, egid); +} + +int SETRESUID(UID_T ruid, UID_T euid, UID_T suid) +{ + TST_CREATE_SYSCALL(setresuid, ruid, euid, suid); +} + +int SETRESGID(GID_T rgid, GID_T egid, GID_T sgid) +{ + TST_CREATE_SYSCALL(setresgid, rgid, egid, sgid); +} + +int FCHOWN(unsigned int fd, UID_T owner, GID_T group) +{ + TST_CREATE_SYSCALL(fchown, fd, owner, group); +} + +int LCHOWN(const char *path, UID_T owner, GID_T group) +{ + TST_CREATE_SYSCALL(lchown, path, owner, group); +} + +int CHOWN(const char *path, UID_T owner, GID_T group) +{ + TST_CREATE_SYSCALL(chown, path, owner, group); +} +#endif /* __LTP_COMPAT_TST_16_H__ */