blob: 104abc315da6cb2b20db26221c8e8bcc0ec5bc8a [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 2002-2004 Roland McGrath <roland@redhat.com>
7 * Copyright (c) 2010 Andreas Schwab <schwab@linux-m68k.org>
8 * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
Elliott Hughesb7556142018-02-20 17:03:16 -08009 * Copyright (c) 2014-2018 The strace developers.
Dmitry V. Levin38a34c92015-12-17 17:56:48 +000010 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
Dmitry V. Levin99a05442014-04-10 14:10:17 +000035#include "defs.h"
36
Elliott Hughesd35df492017-02-15 15:19:05 -080037#ifdef HAVE_STRUCT_USER_DESC
Dmitry V. Levin99a05442014-04-10 14:10:17 +000038
39# include <asm/ldt.h>
40
Elliott Hughesb7556142018-02-20 17:03:16 -080041# include "print_fields.h"
42# include "xstring.h"
43
Dmitry V. Levin99a05442014-04-10 14:10:17 +000044void
Elliott Hughesb7556142018-02-20 17:03:16 -080045print_user_desc(struct tcb *const tcp, const kernel_ulong_t addr,
46 enum user_desc_print_filter filter)
Dmitry V. Levin99a05442014-04-10 14:10:17 +000047{
48 struct user_desc desc;
Elliott Hughesb7556142018-02-20 17:03:16 -080049 unsigned *entry_number = get_tcb_priv_data(tcp);
Dmitry V. Levin99a05442014-04-10 14:10:17 +000050
Elliott Hughesb7556142018-02-20 17:03:16 -080051 switch (filter) {
52 case USER_DESC_ENTERING:
53 if (umove_or_printaddr(tcp, addr, &desc.entry_number))
54 return;
Dmitry V. Levin99a05442014-04-10 14:10:17 +000055
Elliott Hughesb7556142018-02-20 17:03:16 -080056 break;
57
58 case USER_DESC_EXITING:
59 if (!addr || !verbose(tcp))
60 return;
61 if (syserror(tcp) || umove(tcp, addr, &desc)) {
62 if (entry_number)
63 tprints(", ...}");
64
65 return;
66 }
67
68 break;
69
70 case USER_DESC_BOTH:
71 if (umove_or_printaddr(tcp, addr, &desc))
72 return;
73
74 break;
75 }
76
77 if (filter & USER_DESC_ENTERING) {
78 PRINT_FIELD_ID("{", desc, entry_number);
79
80 /*
81 * If we don't print the whole structure now, let's save it for
82 * later.
83 */
84 if (filter == USER_DESC_ENTERING) {
85 entry_number = xmalloc(sizeof(*entry_number));
86
87 *entry_number = desc.entry_number;
88 set_tcb_priv_data(tcp, entry_number, free);
89 }
90 }
91
92 if (filter & USER_DESC_EXITING) {
93 /*
94 * It should be the same in case of get_thread_area, but we can
95 * never be sure...
96 */
97 if (filter == USER_DESC_EXITING) {
98 if (entry_number) {
99 if (*entry_number != desc.entry_number) {
100 if ((int) desc.entry_number == -1)
101 tprints(" => -1");
102 else
103 tprintf(" => %u",
104 desc.entry_number);
105 }
106 } else {
107 /*
108 * This is really strange. If we are here, it
109 * means that we failed on entering but somehow
110 * succeeded on exiting.
111 */
112 PRINT_FIELD_ID(" => {", desc, entry_number);
113 }
114 }
115
116 PRINT_FIELD_0X(", ", desc, base_addr);
117 PRINT_FIELD_0X(", ", desc, limit);
118 PRINT_FIELD_U_CAST(", ", desc, seg_32bit, unsigned int);
119 PRINT_FIELD_U_CAST(", ", desc, contents, unsigned int);
120 PRINT_FIELD_U_CAST(", ", desc, read_exec_only, unsigned int);
121 PRINT_FIELD_U_CAST(", ", desc, limit_in_pages, unsigned int);
122 PRINT_FIELD_U_CAST(", ", desc, seg_not_present, unsigned int);
123 PRINT_FIELD_U_CAST(", ", desc, useable, unsigned int);
124
125# ifdef HAVE_STRUCT_USER_DESC_LM
126 /* lm is totally ignored for 32-bit processes */
127 if (current_klongsize == 8)
128 PRINT_FIELD_U_CAST(", ", desc, lm, unsigned int);
129# endif /* HAVE_STRUCT_USER_DESC_LM */
130
131 tprints("}");
132 }
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000133}
134
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000135SYS_FUNC(modify_ldt)
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000136{
Elliott Hughesb7556142018-02-20 17:03:16 -0800137 if (entering(tcp)) {
138 tprintf("%d, ", (int) tcp->u_arg[0]);
139 if (tcp->u_arg[2] != sizeof(struct user_desc))
140 printaddr(tcp->u_arg[1]);
141 else
142 print_user_desc(tcp, tcp->u_arg[1], USER_DESC_BOTH);
143 tprintf(", %" PRI_klu, tcp->u_arg[2]);
Dmitry V. Levin583526e2015-07-20 00:19:09 +0000144
Elliott Hughesb7556142018-02-20 17:03:16 -0800145 return 0;
146 }
147
148 /*
149 * For some reason ("tht ABI for sys_modify_ldt() expects
150 * 'int'"), modify_ldt clips higher bits on x86_64.
151 */
152
153 if (syserror(tcp) || (kernel_ulong_t) tcp->u_rval < 0xfffff000)
154 return 0;
155
156 tcp->u_error = -(unsigned int) tcp->u_rval;
157
Elliott Hughes28e98bc2018-06-14 16:59:04 -0700158 return 0;
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000159}
160
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000161SYS_FUNC(set_thread_area)
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000162{
163 if (entering(tcp)) {
Elliott Hughesb7556142018-02-20 17:03:16 -0800164 print_user_desc(tcp, tcp->u_arg[0], USER_DESC_BOTH);
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000165 } else {
166 struct user_desc desc;
167
Dmitry V. Levin79a45942015-07-20 00:10:35 +0000168 if (!verbose(tcp) || syserror(tcp) ||
169 umove(tcp, tcp->u_arg[0], &desc) < 0) {
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000170 /* returned entry_number is not available */
171 } else {
172 static char outstr[32];
173
Elliott Hughesb7556142018-02-20 17:03:16 -0800174 xsprintf(outstr, "entry_number=%u", desc.entry_number);
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000175 tcp->auxstr = outstr;
176 return RVAL_STR;
177 }
178 }
179 return 0;
180}
181
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000182SYS_FUNC(get_thread_area)
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000183{
Elliott Hughesb7556142018-02-20 17:03:16 -0800184 print_user_desc(tcp, tcp->u_arg[0],
185 entering(tcp) ? USER_DESC_ENTERING : USER_DESC_EXITING);
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000186 return 0;
187}
188
Elliott Hughesd35df492017-02-15 15:19:05 -0800189#endif /* HAVE_STRUCT_USER_DESC */
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000190
191#if defined(M68K) || defined(MIPS)
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000192SYS_FUNC(set_thread_area)
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000193{
Dmitry V. Levin583526e2015-07-20 00:19:09 +0000194 printaddr(tcp->u_arg[0]);
195
196 return RVAL_DECODED;
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000197
198}
199#endif
200
201#if defined(M68K)
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000202SYS_FUNC(get_thread_area)
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000203{
Dmitry V. Levin583526e2015-07-20 00:19:09 +0000204 return RVAL_DECODED | RVAL_HEX;
Dmitry V. Levin99a05442014-04-10 14:10:17 +0000205}
206#endif