Skip to content

Commit ea64d5a

Browse files
committed
signal: Unify and correct copy_siginfo_to_user32
Among the existing architecture specific versions of copy_siginfo_to_user32 there are several different implementation problems. Some architectures fail to handle all of the cases in in the siginfo union. Some architectures perform a blind copy of the siginfo union when the si_code is negative. A blind copy suggests the data is expected to be in 32bit siginfo format, which means that receiving such a signal via signalfd won't work, or that the data is in 64bit siginfo and the code is copying nonsense to userspace. Create a single instance of copy_siginfo_to_user32 that all of the architectures can share, and teach it to handle all of the cases in the siginfo union correctly, with the assumption that siginfo is stored internally to the kernel is 64bit siginfo format. A special case is made for x86 x32 format. This is needed as presence of both x32 and ia32 on x86_64 results in two different 32bit signal formats. By allowing this small special case there winds up being exactly one code base that needs to be maintained between all of the architectures. Vastly increasing the testing base and the chances of finding bugs. As the x86 copy of copy_siginfo_to_user32 the call of the x86 signal_compat_build_tests were moved into sigaction_compat_abi, so that they will keep running. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent eb5346c commit ea64d5a

16 files changed

Lines changed: 96 additions & 516 deletions

File tree

‎arch/arm64/kernel/signal32.c‎

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -125,76 +125,6 @@ static inline int get_sigset_t(sigset_t *set,
125125
return 0;
126126
}
127127

128-
int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
129-
{
130-
int err;
131-
132-
if (!access_ok(VERIFY_WRITE, to, sizeof(*to)))
133-
return -EFAULT;
134-
135-
/* If you change siginfo_t structure, please be sure
136-
* this code is fixed accordingly.
137-
* It should never copy any pad contained in the structure
138-
* to avoid security leaks, but must copy the generic
139-
* 3 ints plus the relevant union member.
140-
* This routine must convert siginfo from 64bit to 32bit as well
141-
* at the same time.
142-
*/
143-
err = __put_user(from->si_signo, &to->si_signo);
144-
err |= __put_user(from->si_errno, &to->si_errno);
145-
err |= __put_user(from->si_code, &to->si_code);
146-
if (from->si_code < 0)
147-
err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad,
148-
SI_PAD_SIZE);
149-
else switch (siginfo_layout(from->si_signo, from->si_code)) {
150-
case SIL_KILL:
151-
err |= __put_user(from->si_pid, &to->si_pid);
152-
err |= __put_user(from->si_uid, &to->si_uid);
153-
break;
154-
case SIL_TIMER:
155-
err |= __put_user(from->si_tid, &to->si_tid);
156-
err |= __put_user(from->si_overrun, &to->si_overrun);
157-
err |= __put_user(from->si_int, &to->si_int);
158-
break;
159-
case SIL_POLL:
160-
err |= __put_user(from->si_band, &to->si_band);
161-
err |= __put_user(from->si_fd, &to->si_fd);
162-
break;
163-
case SIL_FAULT:
164-
err |= __put_user((compat_uptr_t)(unsigned long)from->si_addr,
165-
&to->si_addr);
166-
#ifdef BUS_MCEERR_AO
167-
/*
168-
* Other callers might not initialize the si_lsb field,
169-
* so check explicitly for the right codes here.
170-
*/
171-
if (from->si_signo == SIGBUS &&
172-
(from->si_code == BUS_MCEERR_AR || from->si_code == BUS_MCEERR_AO))
173-
err |= __put_user(from->si_addr_lsb, &to->si_addr_lsb);
174-
#endif
175-
break;
176-
case SIL_CHLD:
177-
err |= __put_user(from->si_pid, &to->si_pid);
178-
err |= __put_user(from->si_uid, &to->si_uid);
179-
err |= __put_user(from->si_status, &to->si_status);
180-
err |= __put_user(from->si_utime, &to->si_utime);
181-
err |= __put_user(from->si_stime, &to->si_stime);
182-
break;
183-
case SIL_RT:
184-
err |= __put_user(from->si_pid, &to->si_pid);
185-
err |= __put_user(from->si_uid, &to->si_uid);
186-
err |= __put_user(from->si_int, &to->si_int);
187-
break;
188-
case SIL_SYS:
189-
err |= __put_user((compat_uptr_t)(unsigned long)
190-
from->si_call_addr, &to->si_call_addr);
191-
err |= __put_user(from->si_syscall, &to->si_syscall);
192-
err |= __put_user(from->si_arch, &to->si_arch);
193-
break;
194-
}
195-
return err;
196-
}
197-
198128
/*
199129
* VFP save/restore code.
200130
*

‎arch/mips/include/asm/compat.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ typedef u32 compat_old_sigset_t; /* at least 32 bits */
126126

127127
typedef u32 compat_sigset_word;
128128

129-
#define SI_PAD_SIZE32 (128/sizeof(int) - 3)
130-
131129
#define COMPAT_OFF_T_MAX 0x7fffffff
132130

133131
/*

‎arch/mips/kernel/signal32.c‎

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -76,60 +76,3 @@ SYSCALL_DEFINE3(32_sigaction, long, sig, const struct compat_sigaction __user *,
7676

7777
return ret;
7878
}
79-
80-
int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
81-
{
82-
int err;
83-
84-
if (!access_ok (VERIFY_WRITE, to, sizeof(compat_siginfo_t)))
85-
return -EFAULT;
86-
87-
/* If you change siginfo_t structure, please be sure
88-
this code is fixed accordingly.
89-
It should never copy any pad contained in the structure
90-
to avoid security leaks, but must copy the generic
91-
3 ints plus the relevant union member.
92-
This routine must convert siginfo from 64bit to 32bit as well
93-
at the same time. */
94-
err = __put_user(from->si_signo, &to->si_signo);
95-
err |= __put_user(from->si_errno, &to->si_errno);
96-
err |= __put_user(from->si_code, &to->si_code);
97-
if (from->si_code < 0)
98-
err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
99-
else {
100-
switch (siginfo_layout(from->si_signo, from->si_code)) {
101-
case SIL_TIMER:
102-
err |= __put_user(from->si_tid, &to->si_tid);
103-
err |= __put_user(from->si_overrun, &to->si_overrun);
104-
err |= __put_user(from->si_int, &to->si_int);
105-
break;
106-
case SIL_CHLD:
107-
err |= __put_user(from->si_utime, &to->si_utime);
108-
err |= __put_user(from->si_stime, &to->si_stime);
109-
err |= __put_user(from->si_status, &to->si_status);
110-
case SIL_KILL:
111-
err |= __put_user(from->si_pid, &to->si_pid);
112-
err |= __put_user(from->si_uid, &to->si_uid);
113-
break;
114-
case SIL_FAULT:
115-
err |= __put_user((unsigned long)from->si_addr, &to->si_addr);
116-
break;
117-
case SIL_POLL:
118-
err |= __put_user(from->si_band, &to->si_band);
119-
err |= __put_user(from->si_fd, &to->si_fd);
120-
break;
121-
case SIL_RT:
122-
err |= __put_user(from->si_pid, &to->si_pid);
123-
err |= __put_user(from->si_uid, &to->si_uid);
124-
err |= __put_user(from->si_int, &to->si_int);
125-
break;
126-
case SIL_SYS:
127-
err |= __copy_to_user(&to->si_call_addr, &from->si_call_addr,
128-
sizeof(compat_uptr_t));
129-
err |= __put_user(from->si_syscall, &to->si_syscall);
130-
err |= __put_user(from->si_arch, &to->si_arch);
131-
break;
132-
}
133-
}
134-
return err;
135-
}

‎arch/parisc/kernel/signal32.c‎

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -260,65 +260,3 @@ setup_sigcontext32(struct compat_sigcontext __user *sc, struct compat_regfile __
260260

261261
return err;
262262
}
263-
264-
int
265-
copy_siginfo_to_user32 (compat_siginfo_t __user *to, const siginfo_t *from)
266-
{
267-
compat_uptr_t addr;
268-
compat_int_t val;
269-
int err;
270-
271-
if (!access_ok(VERIFY_WRITE, to, sizeof(compat_siginfo_t)))
272-
return -EFAULT;
273-
274-
/* If you change siginfo_t structure, please be sure
275-
this code is fixed accordingly.
276-
It should never copy any pad contained in the structure
277-
to avoid security leaks, but must copy the generic
278-
3 ints plus the relevant union member.
279-
This routine must convert siginfo from 64bit to 32bit as well
280-
at the same time. */
281-
err = __put_user(from->si_signo, &to->si_signo);
282-
err |= __put_user(from->si_errno, &to->si_errno);
283-
err |= __put_user(from->si_code, &to->si_code);
284-
if (from->si_code < 0)
285-
err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
286-
else {
287-
switch (siginfo_layout(from->si_signo, from->si_code)) {
288-
case SIL_CHLD:
289-
err |= __put_user(from->si_utime, &to->si_utime);
290-
err |= __put_user(from->si_stime, &to->si_stime);
291-
err |= __put_user(from->si_status, &to->si_status);
292-
case SIL_KILL:
293-
err |= __put_user(from->si_pid, &to->si_pid);
294-
err |= __put_user(from->si_uid, &to->si_uid);
295-
break;
296-
case SIL_FAULT:
297-
addr = ptr_to_compat(from->si_addr);
298-
err |= __put_user(addr, &to->si_addr);
299-
break;
300-
case SIL_POLL:
301-
err |= __put_user(from->si_band, &to->si_band);
302-
err |= __put_user(from->si_fd, &to->si_fd);
303-
break;
304-
case SIL_TIMER:
305-
err |= __put_user(from->si_tid, &to->si_tid);
306-
err |= __put_user(from->si_overrun, &to->si_overrun);
307-
val = (compat_int_t)from->si_int;
308-
err |= __put_user(val, &to->si_int);
309-
break;
310-
case SIL_RT:
311-
err |= __put_user(from->si_uid, &to->si_uid);
312-
err |= __put_user(from->si_pid, &to->si_pid);
313-
val = (compat_int_t)from->si_int;
314-
err |= __put_user(val, &to->si_int);
315-
break;
316-
case SIL_SYS:
317-
err |= __put_user(ptr_to_compat(from->si_call_addr), &to->si_call_addr);
318-
err |= __put_user(from->si_syscall, &to->si_syscall);
319-
err |= __put_user(from->si_arch, &to->si_arch);
320-
break;
321-
}
322-
}
323-
return err;
324-
}

‎arch/parisc/kernel/signal32.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ struct compat_ucontext {
3434

3535
/* ELF32 signal handling */
3636

37-
int copy_siginfo_to_user32 (compat_siginfo_t __user *to, const siginfo_t *from);
38-
3937
/* In a deft move of uber-hackery, we decide to carry the top half of all
4038
* 64-bit registers in a non-portable, non-ABI, hidden structure.
4139
* Userspace can read the hidden structure if it *wants* but is never

‎arch/powerpc/include/asm/compat.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ typedef u32 compat_old_sigset_t;
119119

120120
typedef u32 compat_sigset_word;
121121

122-
#define SI_PAD_SIZE32 (128/sizeof(int) - 3)
123-
124122
#define COMPAT_OFF_T_MAX 0x7fffffff
125123

126124
/*

‎arch/powerpc/kernel/signal_32.c‎

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -873,63 +873,6 @@ static long restore_tm_user_regs(struct pt_regs *regs,
873873
#endif
874874

875875
#ifdef CONFIG_PPC64
876-
int copy_siginfo_to_user32(struct compat_siginfo __user *d, const siginfo_t *s)
877-
{
878-
int err;
879-
880-
if (!access_ok (VERIFY_WRITE, d, sizeof(*d)))
881-
return -EFAULT;
882-
883-
/* If you change siginfo_t structure, please be sure
884-
* this code is fixed accordingly.
885-
* It should never copy any pad contained in the structure
886-
* to avoid security leaks, but must copy the generic
887-
* 3 ints plus the relevant union member.
888-
* This routine must convert siginfo from 64bit to 32bit as well
889-
* at the same time.
890-
*/
891-
err = __put_user(s->si_signo, &d->si_signo);
892-
err |= __put_user(s->si_errno, &d->si_errno);
893-
err |= __put_user(s->si_code, &d->si_code);
894-
if (s->si_code < 0)
895-
err |= __copy_to_user(&d->_sifields._pad, &s->_sifields._pad,
896-
SI_PAD_SIZE32);
897-
else switch(siginfo_layout(s->si_signo, s->si_code)) {
898-
case SIL_CHLD:
899-
err |= __put_user(s->si_pid, &d->si_pid);
900-
err |= __put_user(s->si_uid, &d->si_uid);
901-
err |= __put_user(s->si_utime, &d->si_utime);
902-
err |= __put_user(s->si_stime, &d->si_stime);
903-
err |= __put_user(s->si_status, &d->si_status);
904-
break;
905-
case SIL_FAULT:
906-
err |= __put_user((unsigned int)(unsigned long)s->si_addr,
907-
&d->si_addr);
908-
break;
909-
case SIL_POLL:
910-
err |= __put_user(s->si_band, &d->si_band);
911-
err |= __put_user(s->si_fd, &d->si_fd);
912-
break;
913-
case SIL_TIMER:
914-
err |= __put_user(s->si_tid, &d->si_tid);
915-
err |= __put_user(s->si_overrun, &d->si_overrun);
916-
err |= __put_user(s->si_int, &d->si_int);
917-
break;
918-
case SIL_SYS:
919-
err |= __put_user(ptr_to_compat(s->si_call_addr), &d->si_call_addr);
920-
err |= __put_user(s->si_syscall, &d->si_syscall);
921-
err |= __put_user(s->si_arch, &d->si_arch);
922-
break;
923-
case SIL_RT:
924-
err |= __put_user(s->si_int, &d->si_int);
925-
/* fallthrough */
926-
case SIL_KILL:
927-
err |= __put_user(s->si_pid, &d->si_pid);
928-
err |= __put_user(s->si_uid, &d->si_uid);
929-
break;
930-
}
931-
return err;
932-
}
933876

934877
#define copy_siginfo_to_user copy_siginfo_to_user32
935878

‎arch/s390/kernel/compat_signal.c‎

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -50,58 +50,6 @@ typedef struct
5050
struct ucontext32 uc;
5151
} rt_sigframe32;
5252

53-
int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
54-
{
55-
int err;
56-
57-
/* If you change siginfo_t structure, please be sure
58-
this code is fixed accordingly.
59-
It should never copy any pad contained in the structure
60-
to avoid security leaks, but must copy the generic
61-
3 ints plus the relevant union member.
62-
This routine must convert siginfo from 64bit to 32bit as well
63-
at the same time. */
64-
err = __put_user(from->si_signo, &to->si_signo);
65-
err |= __put_user(from->si_errno, &to->si_errno);
66-
err |= __put_user(from->si_code, &to->si_code);
67-
if (from->si_code < 0)
68-
err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
69-
else {
70-
switch (siginfo_layout(from->si_signo, from->si_code)) {
71-
case SIL_RT:
72-
err |= __put_user(from->si_int, &to->si_int);
73-
/* fallthrough */
74-
case SIL_KILL:
75-
err |= __put_user(from->si_pid, &to->si_pid);
76-
err |= __put_user(from->si_uid, &to->si_uid);
77-
break;
78-
case SIL_CHLD:
79-
err |= __put_user(from->si_pid, &to->si_pid);
80-
err |= __put_user(from->si_uid, &to->si_uid);
81-
err |= __put_user(from->si_utime, &to->si_utime);
82-
err |= __put_user(from->si_stime, &to->si_stime);
83-
err |= __put_user(from->si_status, &to->si_status);
84-
break;
85-
case SIL_FAULT:
86-
err |= __put_user((unsigned long) from->si_addr,
87-
&to->si_addr);
88-
break;
89-
case SIL_POLL:
90-
err |= __put_user(from->si_band, &to->si_band);
91-
err |= __put_user(from->si_fd, &to->si_fd);
92-
break;
93-
case SIL_TIMER:
94-
err |= __put_user(from->si_tid, &to->si_tid);
95-
err |= __put_user(from->si_overrun, &to->si_overrun);
96-
err |= __put_user(from->si_int, &to->si_int);
97-
break;
98-
default:
99-
break;
100-
}
101-
}
102-
return err ? -EFAULT : 0;
103-
}
104-
10553
/* Store registers needed to create the signal frame */
10654
static void store_sigregs(void)
10755
{

‎arch/sparc/include/asm/compat.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ typedef u32 compat_old_sigset_t;
149149

150150
typedef u32 compat_sigset_word;
151151

152-
#define SI_PAD_SIZE32 (128/sizeof(int) - 3)
153-
154152
#define COMPAT_OFF_T_MAX 0x7fffffff
155153

156154
/*

0 commit comments

Comments
 (0)