36
36
#include <asm/traps.h>
37
37
#include <asm/vdso.h>
38
38
39
- #ifdef CONFIG_ARM64_GCS
40
39
#define GCS_SIGNAL_CAP (addr ) (((unsigned long)addr) & GCS_CAP_ADDR_MASK)
41
40
42
- static bool gcs_signal_cap_valid (u64 addr , u64 val )
43
- {
44
- return val == GCS_SIGNAL_CAP (addr );
45
- }
46
- #endif
47
-
48
41
/*
49
42
* Do a signal return; undo the signal stack. These are aligned to 128-bit.
50
43
*/
@@ -1062,8 +1055,7 @@ static int restore_sigframe(struct pt_regs *regs,
1062
1055
#ifdef CONFIG_ARM64_GCS
1063
1056
static int gcs_restore_signal (void )
1064
1057
{
1065
- unsigned long __user * gcspr_el0 ;
1066
- u64 cap ;
1058
+ u64 gcspr_el0 , cap ;
1067
1059
int ret ;
1068
1060
1069
1061
if (!system_supports_gcs ())
@@ -1072,7 +1064,7 @@ static int gcs_restore_signal(void)
1072
1064
if (!(current -> thread .gcs_el0_mode & PR_SHADOW_STACK_ENABLE ))
1073
1065
return 0 ;
1074
1066
1075
- gcspr_el0 = ( unsigned long __user * ) read_sysreg_s (SYS_GCSPR_EL0 );
1067
+ gcspr_el0 = read_sysreg_s (SYS_GCSPR_EL0 );
1076
1068
1077
1069
/*
1078
1070
* Ensure that any changes to the GCS done via GCS operations
@@ -1087,22 +1079,23 @@ static int gcs_restore_signal(void)
1087
1079
* then faults will be generated on GCS operations - the main
1088
1080
* concern is to protect GCS pages.
1089
1081
*/
1090
- ret = copy_from_user (& cap , gcspr_el0 , sizeof (cap ));
1082
+ ret = copy_from_user (& cap , (unsigned long __user * )gcspr_el0 ,
1083
+ sizeof (cap ));
1091
1084
if (ret )
1092
1085
return - EFAULT ;
1093
1086
1094
1087
/*
1095
1088
* Check that the cap is the actual GCS before replacing it.
1096
1089
*/
1097
- if (! gcs_signal_cap_valid (( u64 ) gcspr_el0 , cap ))
1090
+ if (cap != GCS_SIGNAL_CAP ( gcspr_el0 ))
1098
1091
return - EINVAL ;
1099
1092
1100
1093
/* Invalidate the token to prevent reuse */
1101
- put_user_gcs (0 , (__user void * )gcspr_el0 , & ret );
1094
+ put_user_gcs (0 , (unsigned long __user * )gcspr_el0 , & ret );
1102
1095
if (ret != 0 )
1103
1096
return - EFAULT ;
1104
1097
1105
- write_sysreg_s (gcspr_el0 + 1 , SYS_GCSPR_EL0 );
1098
+ write_sysreg_s (gcspr_el0 + 8 , SYS_GCSPR_EL0 );
1106
1099
1107
1100
return 0 ;
1108
1101
}
@@ -1421,7 +1414,7 @@ static int get_sigframe(struct rt_sigframe_user_layout *user,
1421
1414
1422
1415
static int gcs_signal_entry (__sigrestore_t sigtramp , struct ksignal * ksig )
1423
1416
{
1424
- unsigned long __user * gcspr_el0 ;
1417
+ u64 gcspr_el0 ;
1425
1418
int ret = 0 ;
1426
1419
1427
1420
if (!system_supports_gcs ())
@@ -1434,18 +1427,20 @@ static int gcs_signal_entry(__sigrestore_t sigtramp, struct ksignal *ksig)
1434
1427
* We are entering a signal handler, current register state is
1435
1428
* active.
1436
1429
*/
1437
- gcspr_el0 = ( unsigned long __user * ) read_sysreg_s (SYS_GCSPR_EL0 );
1430
+ gcspr_el0 = read_sysreg_s (SYS_GCSPR_EL0 );
1438
1431
1439
1432
/*
1440
1433
* Push a cap and the GCS entry for the trampoline onto the GCS.
1441
1434
*/
1442
- put_user_gcs ((unsigned long )sigtramp , gcspr_el0 - 2 , & ret );
1443
- put_user_gcs (GCS_SIGNAL_CAP (gcspr_el0 - 1 ), gcspr_el0 - 1 , & ret );
1435
+ put_user_gcs ((unsigned long )sigtramp ,
1436
+ (unsigned long __user * )(gcspr_el0 - 16 ), & ret );
1437
+ put_user_gcs (GCS_SIGNAL_CAP (gcspr_el0 - 8 ),
1438
+ (unsigned long __user * )(gcspr_el0 - 8 ), & ret );
1444
1439
if (ret != 0 )
1445
1440
return ret ;
1446
1441
1447
- gcspr_el0 -= 2 ;
1448
- write_sysreg_s (( unsigned long ) gcspr_el0 , SYS_GCSPR_EL0 );
1442
+ gcspr_el0 -= 16 ;
1443
+ write_sysreg_s (gcspr_el0 , SYS_GCSPR_EL0 );
1449
1444
1450
1445
return 0 ;
1451
1446
}
0 commit comments