1f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin/* 2f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * Check decoding of mount syscall. 3f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * 4f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org> 5f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * All rights reserved. 6f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * 7f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * Redistribution and use in source and binary forms, with or without 8f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * modification, are permitted provided that the following conditions 9f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * are met: 10f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * 1. Redistributions of source code must retain the above copyright 11f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * notice, this list of conditions and the following disclaimer. 12f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * 2. Redistributions in binary form must reproduce the above copyright 13f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * notice, this list of conditions and the following disclaimer in the 14f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * documentation and/or other materials provided with the distribution. 15f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * 3. The name of the author may not be used to endorse or promote products 16f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * derived from this software without specific prior written permission. 17f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * 18f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin */ 29f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 30f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin#include "tests.h" 31f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin#include <stdio.h> 32f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin#include <unistd.h> 33f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin#include <sys/mount.h> 34f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 35f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin#ifndef MS_MGC_VAL 36f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin# define MS_MGC_VAL 0xC0ED0000 37f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin#endif 38f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 39f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin#ifndef MS_RELATIME 40f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin# define MS_RELATIME (1ul << 21) 41f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin#endif 42f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 43f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin#define str_ro_nosuid_nodev_noexec "MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC" 44f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 45f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levinint 46f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levinmain(void) 47f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin{ 48f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin static const char source[] = "mount_source"; 49f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin static const char target[] = "mount_target"; 50f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin static const char fstype[] = "mount_fstype"; 51f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin static const char data[] = "mount_data"; 52f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 53f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin int rc = mount(source, target, fstype, 15, data); 54f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %d %s (%m)\n", 55f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin source, target, fstype, str_ro_nosuid_nodev_noexec, 56f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin data, rc, errno2name()); 57f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 58f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin rc = mount(source, target, fstype, MS_RELATIME | 15, data); 59f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %d %s (%m)\n", 60f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin source, target, fstype, 61f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin str_ro_nosuid_nodev_noexec "|MS_RELATIME", 62f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin data, rc, errno2name()); 63f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 64f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin rc = mount(source, target, fstype, MS_MGC_VAL, data); 65f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %d %s (%m)\n", 66f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin source, target, fstype, "MS_MGC_VAL", data, rc, errno2name()); 67f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 68f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin rc = mount(source, target, fstype, MS_MGC_VAL | 15, data); 69f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin printf("mount(\"%s\", \"%s\", \"%s\", %s, \"%s\") = %d %s (%m)\n", 70f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin source, target, fstype, 71f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin "MS_MGC_VAL|" str_ro_nosuid_nodev_noexec, 72f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin data, rc, errno2name()); 73f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 74f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin rc = mount(source, target, fstype, MS_REMOUNT, data); 75f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin printf("mount(\"%s\", \"%s\", %p, %s, \"%s\") = %d %s (%m)\n", 76f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin source, target, fstype, "MS_REMOUNT", data, rc, errno2name()); 77f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 78f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin rc = mount(source, target, fstype, MS_BIND, data); 79f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin printf("mount(\"%s\", \"%s\", %p, %s, %p) = %d %s (%m)\n", 80f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin source, target, fstype, "MS_BIND", data, rc, errno2name()); 81f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin 82f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin puts("+++ exited with 0 +++"); 83f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin return 0; 84f8da0f3e78d2bc80ca62a73e026a38a17e0a1387Dmitry V. Levin} 85