(root)/
strace-6.5/
tests/
finit_module.c
       1  /*
       2   * Check decoding of finit_module syscall.
       3   *
       4   * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
       5   * Copyright (c) 2016-2022 The strace developers.
       6   * All rights reserved.
       7   *
       8   * SPDX-License-Identifier: GPL-2.0-or-later
       9   */
      10  
      11  #include "tests.h"
      12  
      13  #include "scno.h"
      14  
      15  #if defined(__NR_finit_module)
      16  
      17  # include <stdio.h>
      18  # include <unistd.h>
      19  
      20  # include "init_delete_module.h"
      21  
      22  int
      23  main(void)
      24  {
      25  	static const kernel_ulong_t bogus_fd =
      26  		(kernel_ulong_t) 0xdeb0d1edbeeff00dULL;
      27  
      28  	static const struct {
      29  		kernel_ulong_t val;
      30  		const char *str;
      31  	} flags[] = {
      32  		{ ARG_STR(0) },
      33  		{ (kernel_ulong_t) 0xffffffff00000002ULL,
      34  			"MODULE_INIT_IGNORE_VERMAGIC" },
      35  		{ (kernel_ulong_t) 0xbadc0deddefaced0ULL,
      36  			"0xdefaced0 /* MODULE_INIT_??? */" },
      37  		{ (kernel_ulong_t) 0xfacef157dec0ded1ULL,
      38  			"MODULE_INIT_IGNORE_MODVERSIONS|0xdec0ded0" },
      39  		{ -1LL, "MODULE_INIT_IGNORE_MODVERSIONS|"
      40  			"MODULE_INIT_IGNORE_VERMAGIC|"
      41  			"MODULE_INIT_COMPRESSED_FILE|0xfffffff8" },
      42  	};
      43  
      44  	long rc;
      45  	char *bogus_param1 = tail_alloc(PARAM1_LEN);
      46  	char *bogus_param2 = tail_alloc(PARAM2_LEN);
      47  	const char *errstr;
      48  
      49  	fill_memory_ex(bogus_param1, PARAM1_LEN, PARAM1_BASE, PARAM1_LEN);
      50  	fill_memory_ex(bogus_param2, PARAM2_LEN, PARAM2_BASE, PARAM2_LEN);
      51  
      52  	rc = syscall(__NR_finit_module, F8ILL_KULONG_MASK, NULL,
      53  		     F8ILL_KULONG_MASK);
      54  	printf("finit_module(0, NULL, 0) = %s\n", sprintrc(rc));
      55  
      56  	rc = syscall(__NR_finit_module, bogus_fd, bogus_param1, flags[0].val);
      57  	errstr = sprintrc(rc);
      58  
      59  	printf("finit_module(%d, \"", (int) bogus_fd);
      60  	print_str(PARAM1_BASE, MAX_STRLEN, false);
      61  	printf("\"..., %s) = %s\n", flags[0].str, errstr);
      62  
      63  	bogus_param1[PARAM1_LEN - 1] = '\0';
      64  
      65  	rc = syscall(__NR_finit_module, bogus_fd, bogus_param1, flags[1].val);
      66  	errstr = sprintrc(rc);
      67  
      68  	printf("finit_module(%d, \"", (int) bogus_fd);
      69  	print_str(PARAM1_BASE, MAX_STRLEN, false);
      70  	printf("\", %s) = %s\n", flags[1].str, errstr);
      71  
      72  	rc = syscall(__NR_finit_module, bogus_fd, bogus_param2 + PARAM2_LEN,
      73  		flags[2].val);
      74  	printf("finit_module(%d, %p, %s) = %s\n",
      75  	       (int) bogus_fd, bogus_param2 + PARAM2_LEN, flags[2].str,
      76  	       sprintrc(rc));
      77  
      78  	rc = syscall(__NR_finit_module, bogus_fd, bogus_param2, flags[3].val);
      79  	printf("finit_module(%d, %p, %s) = %s\n",
      80  	       (int) bogus_fd, bogus_param2, flags[3].str, sprintrc(rc));
      81  
      82  	bogus_param2[PARAM2_LEN - 1] = '\0';
      83  
      84  	rc = syscall(__NR_finit_module, bogus_fd, bogus_param2, flags[4].val);
      85  	errstr = sprintrc(rc);
      86  
      87  	printf("finit_module(%d, \"", (int) bogus_fd);
      88  	print_str(PARAM2_BASE, PARAM2_LEN - 1, true);
      89  	printf("\", %s) = %s\n", flags[4].str, errstr);
      90  
      91  	puts("+++ exited with 0 +++");
      92  
      93  	return 0;
      94  }
      95  
      96  #else
      97  
      98  SKIP_MAIN_UNDEFINED("__NR_finit_module");
      99  
     100  #endif