(root)/
strace-6.5/
tests-mx32/
init_module.c
       1  /*
       2   * Check decoding of init_module syscall.
       3   *
       4   * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
       5   * Copyright (c) 2016-2019 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_init_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  
      26  	static const kernel_ulong_t bogus_addr =
      27  		(kernel_ulong_t) 0xfffffeedfffffaceULL;
      28  	static const kernel_ulong_t bogus_len =
      29  		(kernel_ulong_t) 0xfffffca7ffffc0deULL;
      30  
      31  	long rc;
      32  	char *bogus_param1 = tail_alloc(PARAM1_LEN);
      33  	char *bogus_param2 = tail_alloc(PARAM2_LEN);
      34  	const char *errstr;
      35  
      36  	fill_memory_ex(bogus_param1, PARAM1_LEN, PARAM1_BASE, PARAM1_LEN);
      37  	fill_memory_ex(bogus_param2, PARAM2_LEN, PARAM2_BASE, PARAM2_LEN);
      38  
      39  	rc = syscall(__NR_init_module, NULL, F8ILL_KULONG_MASK, NULL);
      40  	printf("init_module(NULL, %llu, NULL) = %s\n",
      41  	       (unsigned long long) F8ILL_KULONG_MASK, sprintrc(rc));
      42  
      43  	rc = syscall(__NR_init_module, bogus_addr, 0, bogus_param1);
      44  	errstr = sprintrc(rc);
      45  
      46  	printf("init_module(%#llx, 0, \"", (unsigned long long) bogus_addr);
      47  	print_str(PARAM1_BASE, MAX_STRLEN, false);
      48  	printf("\"...) = %s\n", errstr);
      49  
      50  	bogus_param1[PARAM1_LEN - 1] = '\0';
      51  
      52  	rc = syscall(__NR_init_module, bogus_addr, 0, bogus_param1);
      53  	errstr = sprintrc(rc);
      54  
      55  	printf("init_module(%#llx, 0, \"", (unsigned long long) bogus_addr);
      56  	print_str(PARAM1_BASE, MAX_STRLEN, false);
      57  	printf("\") = %s\n", errstr);
      58  
      59  	rc = syscall(__NR_init_module, bogus_addr, bogus_len,
      60  		bogus_param2 + PARAM2_LEN);
      61  	printf("init_module(%#llx, %llu, %p) = %s\n",
      62  	       (unsigned long long) bogus_addr, (unsigned long long) bogus_len,
      63  	       bogus_param2 + PARAM2_LEN, sprintrc(rc));
      64  
      65  	rc = syscall(__NR_init_module, NULL, bogus_len, bogus_param2);
      66  	printf("init_module(NULL, %llu, %p) = %s\n",
      67  	       (unsigned long long) bogus_len, bogus_param2, sprintrc(rc));
      68  
      69  	bogus_param2[PARAM2_LEN - 1] = '\0';
      70  
      71  	rc = syscall(__NR_init_module, NULL, bogus_len, bogus_param2);
      72  	errstr = sprintrc(rc);
      73  
      74  	printf("init_module(NULL, %llu, \"", (unsigned long long) bogus_len);
      75  	print_str(PARAM2_BASE, PARAM2_LEN - 1, true);
      76  	printf("\") = %s\n", errstr);
      77  
      78  	puts("+++ exited with 0 +++");
      79  
      80  	return 0;
      81  }
      82  
      83  #else
      84  
      85  SKIP_MAIN_UNDEFINED("__NR_init_module");
      86  
      87  #endif