Skip to content

Commit 9f64643

Browse files
author
CKI KWF Bot
committed
Merge: Provide lockdown-compatible user ABI for librtas
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7454 Description: Provide lockdown-compatible user ABI for librtas JIRA: https://issues.redhat.com/browse/RHEL-101838 Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=68939164 Tested: Verified Brew build test kernel RPMs and confirmed working as designed Signed-off-by: Mamatha Inamdar <minamdar@redhat.com> Approved-by: Steve Best <sbest@redhat.com> Approved-by: Tony Camuso <tcamuso@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents 108d291 + 8bf0aaa commit 9f64643

File tree

13 files changed

+1743
-317
lines changed

13 files changed

+1743
-317
lines changed

Documentation/userspace-api/ioctl/ioctl-number.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ Code Seq# Include File Comments
350350
<mailto:linuxppc-dev>
351351
0xB2 01-02 arch/powerpc/include/uapi/asm/papr-sysparm.h powerpc/pseries system parameter API
352352
<mailto:linuxppc-dev>
353+
0xB2 03-05 arch/powerpc/include/uapi/asm/papr-indices.h powerpc/pseries indices API
354+
<mailto:linuxppc-dev>
355+
0xB2 06-07 arch/powerpc/include/uapi/asm/papr-platform-dump.h powerpc/pseries Platform Dump API
356+
<mailto:linuxppc-dev>
357+
0xB2 08 powerpc/include/uapi/asm/papr-physical-attestation.h powerpc/pseries Physical Attestation API
358+
<mailto:linuxppc-dev>
353359
0xB3 00 linux/mmc/ioctl.h
354360
0xB4 00-0F linux/gpio.h <mailto:linux-gpio@vger.kernel.org>
355361
0xB5 00-0F uapi/linux/rpmsg.h <mailto:linux-remoteproc@vger.kernel.org>

arch/powerpc/include/asm/rtas.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ extern char rtas_data_buf[RTAS_DATA_BUF_SIZE];
337337
extern unsigned long rtas_rmo_buf;
338338

339339
extern struct mutex rtas_ibm_get_vpd_lock;
340+
extern struct mutex rtas_ibm_get_indices_lock;
341+
extern struct mutex rtas_ibm_set_dynamic_indicator_lock;
342+
extern struct mutex rtas_ibm_get_dynamic_sensor_state_lock;
343+
extern struct mutex rtas_ibm_physical_attestation_lock;
340344

341345
#define GLOBAL_INTERRUPT_QUEUE 9005
342346

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
#ifndef _UAPI_PAPR_INDICES_H_
3+
#define _UAPI_PAPR_INDICES_H_
4+
5+
#include <linux/types.h>
6+
#include <asm/ioctl.h>
7+
#include <asm/papr-miscdev.h>
8+
9+
#define LOC_CODE_SIZE 80
10+
#define RTAS_GET_INDICES_BUF_SIZE SZ_4K
11+
12+
struct papr_indices_io_block {
13+
union {
14+
struct {
15+
__u8 is_sensor; /* 0 for indicator and 1 for sensor */
16+
__u32 indice_type;
17+
} indices;
18+
struct {
19+
__u32 token; /* Sensor or indicator token */
20+
__u32 state; /* get / set state */
21+
/*
22+
* PAPR+ 12.3.2.4 Converged Location Code Rules - Length
23+
* Restrictions. 79 characters plus null.
24+
*/
25+
char location_code_str[LOC_CODE_SIZE]; /* location code */
26+
} dynamic_param;
27+
};
28+
};
29+
30+
/*
31+
* ioctls for /dev/papr-indices.
32+
* PAPR_INDICES_IOC_GET: Returns a get-indices handle fd to read data
33+
* PAPR_DYNAMIC_SENSOR_IOC_GET: Gets the state of the input sensor
34+
* PAPR_DYNAMIC_INDICATOR_IOC_SET: Sets the new state for the input indicator
35+
*/
36+
#define PAPR_INDICES_IOC_GET _IOW(PAPR_MISCDEV_IOC_ID, 3, struct papr_indices_io_block)
37+
#define PAPR_DYNAMIC_SENSOR_IOC_GET _IOWR(PAPR_MISCDEV_IOC_ID, 4, struct papr_indices_io_block)
38+
#define PAPR_DYNAMIC_INDICATOR_IOC_SET _IOW(PAPR_MISCDEV_IOC_ID, 5, struct papr_indices_io_block)
39+
40+
41+
#endif /* _UAPI_PAPR_INDICES_H_ */
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
#ifndef _UAPI_PAPR_PHYSICAL_ATTESTATION_H_
3+
#define _UAPI_PAPR_PHYSICAL_ATTESTATION_H_
4+
5+
#include <linux/types.h>
6+
#include <asm/ioctl.h>
7+
#include <asm/papr-miscdev.h>
8+
9+
#define PAPR_PHYATTEST_MAX_INPUT 4084 /* Max 4K buffer: 4K-12 */
10+
11+
/*
12+
* Defined in PAPR 2.13+ 21.6 Attestation Command Structures.
13+
* User space pass this struct and the max size should be 4K.
14+
*/
15+
struct papr_phy_attest_io_block {
16+
__u8 version;
17+
__u8 command;
18+
__u8 TCG_major_ver;
19+
__u8 TCG_minor_ver;
20+
__be32 length;
21+
__be32 correlator;
22+
__u8 payload[PAPR_PHYATTEST_MAX_INPUT];
23+
};
24+
25+
/*
26+
* ioctl for /dev/papr-physical-attestation. Returns a attestation
27+
* command fd handle
28+
*/
29+
#define PAPR_PHY_ATTEST_IOC_HANDLE _IOW(PAPR_MISCDEV_IOC_ID, 8, struct papr_phy_attest_io_block)
30+
31+
#endif /* _UAPI_PAPR_PHYSICAL_ATTESTATION_H_ */
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
#ifndef _UAPI_PAPR_PLATFORM_DUMP_H_
3+
#define _UAPI_PAPR_PLATFORM_DUMP_H_
4+
5+
#include <linux/types.h>
6+
#include <asm/ioctl.h>
7+
#include <asm/papr-miscdev.h>
8+
9+
/*
10+
* ioctl for /dev/papr-platform-dump. Returns a platform-dump handle fd
11+
* corresponding to dump tag.
12+
*/
13+
#define PAPR_PLATFORM_DUMP_IOC_CREATE_HANDLE _IOW(PAPR_MISCDEV_IOC_ID, 6, __u64)
14+
#define PAPR_PLATFORM_DUMP_IOC_INVALIDATE _IOW(PAPR_MISCDEV_IOC_ID, 7, __u64)
15+
16+
#endif /* _UAPI_PAPR_PLATFORM_DUMP_H_ */

arch/powerpc/kernel/rtas.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ unsigned long rtas_rmo_buf;
7676
void (*rtas_flash_term_hook)(int);
7777
EXPORT_SYMBOL(rtas_flash_term_hook);
7878

79+
DEFINE_MUTEX(rtas_ibm_physical_attestation_lock);
7980
DEFINE_MUTEX(rtas_ibm_get_vpd_lock);
81+
DEFINE_MUTEX(rtas_ibm_get_indices_lock);
82+
DEFINE_MUTEX(rtas_ibm_set_dynamic_indicator_lock);
83+
DEFINE_MUTEX(rtas_ibm_get_dynamic_sensor_state_lock);
8084

8185
/* RTAS use home made raw locking instead of spin_lock_irqsave
8286
* because those can be called from within really nasty contexts
@@ -1108,14 +1112,39 @@ static void __init rtas_syscall_filter_init(void)
11081112

11091113
#endif /* CONFIG_PPC_RTAS_FILTER */
11101114

1115+
/*
1116+
* For specific RTAS calls, mutex will be held before
1117+
* RTAS enter. Return the mutex struct for those
1118+
* specific RTAS tokens.
1119+
*/
1120+
static struct mutex *find_rtas_mutex(int token)
1121+
{
1122+
if (token == rtas_token("ibm,get-vpd"))
1123+
return &rtas_ibm_get_vpd_lock;
1124+
1125+
if (token == rtas_token("ibm,get-indices"))
1126+
return &rtas_ibm_get_indices_lock;
1127+
1128+
if (token == rtas_token("ibm,set-dynamic-indicator"))
1129+
return &rtas_ibm_set_dynamic_indicator_lock;
1130+
1131+
if (token == rtas_token("ibm,get-dynamic-sensor-state"))
1132+
return &rtas_ibm_get_dynamic_sensor_state_lock;
1133+
1134+
if (token == rtas_token("ibm,physical-attestation"))
1135+
return &rtas_ibm_physical_attestation_lock;
1136+
1137+
return NULL;
1138+
}
1139+
11111140
/* We assume to be passed big endian arguments */
11121141
SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
11131142
{
11141143
struct rtas_args args;
11151144
unsigned long flags;
11161145
char *buff_copy, *errbuf = NULL;
11171146
int nargs, nret, token;
1118-
bool is_get_vpd;
1147+
struct mutex *rtas_token_mutex = NULL;
11191148

11201149
if (!capable(CAP_SYS_ADMIN))
11211150
return -EPERM;
@@ -1171,9 +1200,12 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
11711200

11721201
buff_copy = get_errorlog_buffer();
11731202

1174-
is_get_vpd = (token == rtas_token("ibm,get-vpd"));
1175-
if (is_get_vpd)
1176-
mutex_lock(&rtas_ibm_get_vpd_lock);
1203+
/*
1204+
* Hold mutex only for specific RTAS calls.
1205+
*/
1206+
rtas_token_mutex = find_rtas_mutex(token);
1207+
if (rtas_token_mutex)
1208+
mutex_lock(rtas_token_mutex);
11771209

11781210
flags = lock_rtas();
11791211

@@ -1188,8 +1220,8 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
11881220

11891221
unlock_rtas(flags);
11901222

1191-
if (is_get_vpd)
1192-
mutex_unlock(&rtas_ibm_get_vpd_lock);
1223+
if (rtas_token_mutex)
1224+
mutex_unlock(rtas_token_mutex);
11931225

11941226
if (buff_copy) {
11951227
if (errbuf)

arch/powerpc/platforms/pseries/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ ccflags-$(CONFIG_PPC_PSERIES_DEBUG) += -DDEBUG
44

55
obj-y := lpar.o hvCall.o nvram.o reconfig.o \
66
of_helpers.o rtas-work-area.o papr-sysparm.o \
7-
papr-vpd.o \
7+
papr-rtas-common.o papr-vpd.o papr-indices.o \
8+
papr-platform-dump.o papr-phy-attest.o \
89
setup.o iommu.o event_sources.o ras.o \
910
firmware.o power.o dlpar.o mobility.o rng.o \
1011
pci.o pci_dlpar.o eeh_pseries.o msi.o \

0 commit comments

Comments
 (0)