Home | History | Annotate | Download | only in tests-mx32
      1 /*
      2  * Check decoding of mount syscall.
      3  *
      4  * Copyright (c) 2016 Dmitry V. Levin <ldv (at) altlinux.org>
      5  * Copyright (c) 2016-2018 The strace developers.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. The name of the author may not be used to endorse or promote products
     17  *    derived from this software without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "tests.h"
     32 #include <stdio.h>
     33 #include <unistd.h>
     34 #include <sys/mount.h>
     35 
     36 #ifndef MS_MGC_VAL
     37 # define MS_MGC_VAL 0xC0ED0000
     38 #endif
     39 
     40 #ifndef MS_RELATIME
     41 # define MS_RELATIME (1ul << 21)
     42 #endif
     43 
     44 #if XLAT_RAW
     45 # define str_unknown "0x300"
     46 # define str_submount_200 "0x4000200"
     47 # define str_mgc_val "0xc0ed0000"
     48 # define str_remount "0x20"
     49 # define str_bind "0x1000"
     50 # define str_ro_nosuid_nodev_noexec "0xf"
     51 # define str_ro_nosuid_nodev_noexec_relatime "0x20000f"
     52 #elif XLAT_VERBOSE
     53 # define str_unknown "0x300 /* MS_??? */"
     54 # define str_submount_200 "0x4000200 /* MS_SUBMOUNT|0x200 */"
     55 # define str_mgc_val "0xc0ed0000 /* MS_MGC_VAL */"
     56 # define str_remount "0x20 /* MS_REMOUNT */"
     57 # define str_bind "0x1000 /* MS_BIND */"
     58 # define str_ro_nosuid_nodev_noexec \
     59 	"0xf /* MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC */"
     60 # define str_ro_nosuid_nodev_noexec_relatime \
     61 	"0x20000f /* MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_RELATIME */"
     62 #else /* !XLAT_RAW && !XLAT_VERBOSE */
     63 # define str_unknown "0x300 /* MS_??? */"
     64 # define str_submount_200 "MS_SUBMOUNT|0x200"
     65 # define str_mgc_val "MS_MGC_VAL"
     66 # define str_remount "MS_REMOUNT"
     67 # define str_bind "MS_BIND"
     68 # define str_ro_nosuid_nodev_noexec "MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC"
     69 # define str_ro_nosuid_nodev_noexec_relatime \
     70 	"MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_RELATIME"
     71 #endif /* XLAT_RAW, XLAT_VERBOSE */
     72 
     73 int
     74 main(void)
     75 {
     76 	static const char source[] = "mount_source";
     77 	static const char target[] = "mount_target";
     78 	static const char fstype[] = "mount_fstype";
     79 	static const char data[] = "mount_data";
     80 	TAIL_ALLOC_OBJECT_CONST_PTR(char, bogus);
     81 
     82 	bogus[0] = 'a';
     83 
     84 	int rc = mount(NULL, NULL, NULL, 0, NULL);
     85 	printf("mount(NULL, NULL, NULL, 0, NULL) = %s\n",
     86 	       sprintrc(rc));
     87 
     88 	rc = mount(bogus, bogus, bogus, 768, bogus);
     89 	printf("mount(%p, %p, %p, %s, %p) = %s\n",
     90 	       bogus, bogus, bogus, str_unknown, bogus, sprintrc(rc));
     91 
     92 	rc = mount(bogus + 1, bogus + 1, bogus + 1, 0x4000200, bogus + 1);
     93 	printf("mount(%p, %p, %p, %s, %p) = %s\n",
     94 	       bogus + 1, bogus + 1, bogus + 1, str_submount_200,
     95 	       bogus + 1, sprintrc(rc));
     96 
     97 	rc = mount(source, target, fstype, 15, data);
     98 	printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %s\n",
     99 	       source, target, fstype, str_ro_nosuid_nodev_noexec,
    100 	       data, sprintrc(rc));
    101 
    102 	rc = mount(source, target, fstype, MS_RELATIME | 15, data);
    103 	printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %s\n",
    104 	       source, target, fstype,
    105 	       str_ro_nosuid_nodev_noexec_relatime,
    106 	       data, sprintrc(rc));
    107 
    108 	rc = mount(source, target, fstype, MS_MGC_VAL, data);
    109 	printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %s\n",
    110 	       source, target, fstype, str_mgc_val, data, sprintrc(rc));
    111 
    112 	rc = mount(source, target, fstype, MS_MGC_VAL | 15, data);
    113 	printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %s\n",
    114 	       source, target, fstype,
    115 	       str_mgc_val "|" str_ro_nosuid_nodev_noexec,
    116 	       data, sprintrc(rc));
    117 
    118 	rc = mount(source, target, NULL, MS_REMOUNT, data);
    119 	printf("mount(\"%s\", \"%s\", NULL, %s, \"%s\") = %s\n",
    120 	       source, target, str_remount, data, sprintrc(rc));
    121 
    122 	rc = mount(source, target, fstype, MS_REMOUNT, data);
    123 	printf("mount(\"%s\", \"%s\", %p, %s, \"%s\") = %s\n",
    124 	       source, target, fstype, str_remount, data, sprintrc(rc));
    125 
    126 	rc = mount(source, target, NULL, MS_BIND, data);
    127 	printf("mount(\"%s\", \"%s\", NULL, %s, %p) = %s\n",
    128 	       source, target, str_bind, data, sprintrc(rc));
    129 
    130 	rc = mount(source, target, fstype, MS_BIND, NULL);
    131 	printf("mount(\"%s\", \"%s\", %p, %s, NULL) = %s\n",
    132 	       source, target, fstype, str_bind, sprintrc(rc));
    133 
    134 	puts("+++ exited with 0 +++");
    135 	return 0;
    136 }
    137