Apply transparent_union attribute to union semun
PATCH 1/1 Apply transparent_union attribute to union semun
From: Jonas Bonn <[email protected]>
The syscall handler for semctl is written under the assumption that the toolchain will pass "small" unions as function parameters directly instead of by reference. The union semun is "small" and thus fits this description.
Since it is assumed that the union will be passed directly and not by reference, it is safe to access the union members without going via get_user.
The OpenRISC architecture, however, passes all unions by reference, thus breaking the above assumption.
The technically correct fix here is to mark the union as being transparent so that the ABI of the union's first element determines the parameter passing method and thus make explicit what's already implied in the function definition.
--- include/linux/sem.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/sem.h +1 -1
@@ -48,7 +48,7 @@ union semun {unsigned short __user *array;/* array for GETALL & SETALL */ struct seminfo __user *__buf;/* buffer for IPC_INFO */ void __user *__pad; -}; +} __attribute__ ((transparent_union));struct seminfo {int semmap;
Signature · 1 line
1.7.4.1
Quoted 6 lines · On Fri, 2011-05-27 at 00:27 +0200, [email protected] wrote:
From: Jonas Bonn <[email protected]>
The syscall handler for semctl is written under the assumption that the toolchain will pass "small" unions as function parameters directly instead of by reference. The union semun is "small" and thus fits this description.
Quoted 6 lines
Since it is assumed that the union will be passed directly and not by reference, it is safe to access the union members without going via
get_user.The OpenRISC architecture, however, passes all unions by reference, thus breaking the above assumption.
Hi Jonas
Joern and I were discussing this - there is a case for changing the ABI. It would certainly fix a debugging issue.
Quoted 15 lines
The technically correct fix here is to mark the union as being transparent so that the ABI of the union's first element determines the parameter passing method and thus make explicit what's already implied in the function definition.
Signed-off-by Jonas Bonn <[email protected]>--- include/linux/sem.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)include/linux/sem.h +0
-0
include/linux/sem.h union semun { · line 54
Quoted 8 lines
include/linux/sem.h +1
-1@@ -48,7 +48,7 @@ union semun {unsigned short __user *array;/* array for GETALL & SETALL */ struct seminfo __user *__buf;/* buffer for IPC_INFO */ void __user *__pad; -}; +} __attribute__ ((transparent_union));struct seminfo {int semmap;
Excellent. Semaphore test now passes. I look forward to rerunning regression - we may be down to a single failure now!
Best wishes,
Jeremy
Signature · 5 lines
Tel: +44 (1590) 610184 Cell: +44 (7970) 676050 SkypeID: jeremybennett Email: [email protected] Web: www.embecosm.com
Hi,
I never got any feedback on this patch... is this an acceptable solution for upstream? ...or is the usage of this GCC extension discouraged? /Jonas
Quoted 36 lines · On Fri, 2011-05-27 at 00:27 +0200, [email protected] wrote:
From: Jonas Bonn <[email protected]>
The syscall handler for semctl is written under the assumption that the toolchain will pass "small" unions as function parameters directly instead of by reference. The union semun is "small" and thus fits this description.
Since it is assumed that the union will be passed directly and not by reference, it is safe to access the union members without going via
get_user.The OpenRISC architecture, however, passes all unions by reference, thus breaking the above assumption.
The technically correct fix here is to mark the union as being transparent so that the ABI of the union's first element determines the parameter passing method and thus make explicit what's already implied in the function definition.
Signed-off-by Jonas Bonn <[email protected]>--- include/linux/sem.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)include/linux/sem.h +1
-1@@ -48,7 +48,7 @@ union semun {unsigned short __user *array;/* array for GETALL & SETALL */ struct seminfo __user *__buf;/* buffer for IPC_INFO */ void __user *__pad; -}; +} __attribute__ ((transparent_union));struct seminfo {int semmap;