Skip to content

Commit 3b81d8b

Browse files
Nick CrewsEnric Balletbo i Serra
authored andcommitted
platform/chrome: wilco_ec: Add batt_ppid_info command to telemetry driver
Add the GET_BATT_PPID_INFO=0x8A command to the allowlist of accepted telemetry commands. In addition, since this new command requires verifying the contents of some of the arguments, I also restructure the request to use a union of the argument structs. Also, zero out the request buffer before each request, and change "whitelist" to "allowlist". Signed-off-by: Nick Crews <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]>
1 parent 5f9e832 commit 3b81d8b

File tree

1 file changed

+43
-21
lines changed

1 file changed

+43
-21
lines changed

drivers/platform/chrome/wilco_ec/telemetry.c

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* the OS sends a command to the EC via a write() to a char device,
1010
* and can read the response with a read(). The write() request is
1111
* verified by the driver to ensure that it is performing only one
12-
* of the whitelisted commands, and that no extraneous data is
12+
* of the allowlisted commands, and that no extraneous data is
1313
* being transmitted to the EC. The response is passed directly
1414
* back to the reader with no modification.
1515
*
@@ -59,21 +59,10 @@ static DEFINE_IDA(telem_ida);
5959
#define WILCO_EC_TELEM_GET_TEMP_INFO 0x95
6060
#define WILCO_EC_TELEM_GET_TEMP_READ 0x2C
6161
#define WILCO_EC_TELEM_GET_BATT_EXT_INFO 0x07
62+
#define WILCO_EC_TELEM_GET_BATT_PPID_INFO 0x8A
6263

6364
#define TELEM_ARGS_SIZE_MAX 30
6465

65-
/**
66-
* struct wilco_ec_telem_request - Telemetry command and arguments sent to EC.
67-
* @command: One of WILCO_EC_TELEM_GET_* command codes.
68-
* @reserved: Must be 0.
69-
* @args: The first N bytes are one of telem_args_get_* structs, the rest is 0.
70-
*/
71-
struct wilco_ec_telem_request {
72-
u8 command;
73-
u8 reserved;
74-
u8 args[TELEM_ARGS_SIZE_MAX];
75-
} __packed;
76-
7766
/*
7867
* The following telem_args_get_* structs are embedded within the |args| field
7968
* of wilco_ec_telem_request.
@@ -122,6 +111,32 @@ struct telem_args_get_batt_ext_info {
122111
u8 var_args[5];
123112
} __packed;
124113

114+
struct telem_args_get_batt_ppid_info {
115+
u8 always1; /* Should always be 1 */
116+
} __packed;
117+
118+
/**
119+
* struct wilco_ec_telem_request - Telemetry command and arguments sent to EC.
120+
* @command: One of WILCO_EC_TELEM_GET_* command codes.
121+
* @reserved: Must be 0.
122+
* @args: The first N bytes are one of telem_args_get_* structs, the rest is 0.
123+
*/
124+
struct wilco_ec_telem_request {
125+
u8 command;
126+
u8 reserved;
127+
union {
128+
u8 buf[TELEM_ARGS_SIZE_MAX];
129+
struct telem_args_get_log get_log;
130+
struct telem_args_get_version get_version;
131+
struct telem_args_get_fan_info get_fan_info;
132+
struct telem_args_get_diag_info get_diag_info;
133+
struct telem_args_get_temp_info get_temp_info;
134+
struct telem_args_get_temp_read get_temp_read;
135+
struct telem_args_get_batt_ext_info get_batt_ext_info;
136+
struct telem_args_get_batt_ppid_info get_batt_ppid_info;
137+
} args;
138+
} __packed;
139+
125140
/**
126141
* check_telem_request() - Ensure that a request from userspace is valid.
127142
* @rq: Request buffer copied from userspace.
@@ -133,7 +148,7 @@ struct telem_args_get_batt_ext_info {
133148
* We do not want to allow userspace to send arbitrary telemetry commands to
134149
* the EC. Therefore we check to ensure that
135150
* 1. The request follows the format of struct wilco_ec_telem_request.
136-
* 2. The supplied command code is one of the whitelisted commands.
151+
* 2. The supplied command code is one of the allowlisted commands.
137152
* 3. The request only contains the necessary data for the header and arguments.
138153
*/
139154
static int check_telem_request(struct wilco_ec_telem_request *rq,
@@ -146,25 +161,31 @@ static int check_telem_request(struct wilco_ec_telem_request *rq,
146161

147162
switch (rq->command) {
148163
case WILCO_EC_TELEM_GET_LOG:
149-
max_size += sizeof(struct telem_args_get_log);
164+
max_size += sizeof(rq->args.get_log);
150165
break;
151166
case WILCO_EC_TELEM_GET_VERSION:
152-
max_size += sizeof(struct telem_args_get_version);
167+
max_size += sizeof(rq->args.get_version);
153168
break;
154169
case WILCO_EC_TELEM_GET_FAN_INFO:
155-
max_size += sizeof(struct telem_args_get_fan_info);
170+
max_size += sizeof(rq->args.get_fan_info);
156171
break;
157172
case WILCO_EC_TELEM_GET_DIAG_INFO:
158-
max_size += sizeof(struct telem_args_get_diag_info);
173+
max_size += sizeof(rq->args.get_diag_info);
159174
break;
160175
case WILCO_EC_TELEM_GET_TEMP_INFO:
161-
max_size += sizeof(struct telem_args_get_temp_info);
176+
max_size += sizeof(rq->args.get_temp_info);
162177
break;
163178
case WILCO_EC_TELEM_GET_TEMP_READ:
164-
max_size += sizeof(struct telem_args_get_temp_read);
179+
max_size += sizeof(rq->args.get_temp_read);
165180
break;
166181
case WILCO_EC_TELEM_GET_BATT_EXT_INFO:
167-
max_size += sizeof(struct telem_args_get_batt_ext_info);
182+
max_size += sizeof(rq->args.get_batt_ext_info);
183+
break;
184+
case WILCO_EC_TELEM_GET_BATT_PPID_INFO:
185+
if (rq->args.get_batt_ppid_info.always1 != 1)
186+
return -EINVAL;
187+
188+
max_size += sizeof(rq->args.get_batt_ppid_info);
168189
break;
169190
default:
170191
return -EINVAL;
@@ -250,6 +271,7 @@ static ssize_t telem_write(struct file *filp, const char __user *buf,
250271

251272
if (count > sizeof(sess_data->request))
252273
return -EMSGSIZE;
274+
memset(&sess_data->request, 0, sizeof(sess_data->request));
253275
if (copy_from_user(&sess_data->request, buf, count))
254276
return -EFAULT;
255277
ret = check_telem_request(&sess_data->request, count);

0 commit comments

Comments
 (0)