9
9
* the OS sends a command to the EC via a write() to a char device,
10
10
* and can read the response with a read(). The write() request is
11
11
* 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
13
13
* being transmitted to the EC. The response is passed directly
14
14
* back to the reader with no modification.
15
15
*
@@ -59,21 +59,10 @@ static DEFINE_IDA(telem_ida);
59
59
#define WILCO_EC_TELEM_GET_TEMP_INFO 0x95
60
60
#define WILCO_EC_TELEM_GET_TEMP_READ 0x2C
61
61
#define WILCO_EC_TELEM_GET_BATT_EXT_INFO 0x07
62
+ #define WILCO_EC_TELEM_GET_BATT_PPID_INFO 0x8A
62
63
63
64
#define TELEM_ARGS_SIZE_MAX 30
64
65
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
-
77
66
/*
78
67
* The following telem_args_get_* structs are embedded within the |args| field
79
68
* of wilco_ec_telem_request.
@@ -122,6 +111,32 @@ struct telem_args_get_batt_ext_info {
122
111
u8 var_args [5 ];
123
112
} __packed ;
124
113
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
+
125
140
/**
126
141
* check_telem_request() - Ensure that a request from userspace is valid.
127
142
* @rq: Request buffer copied from userspace.
@@ -133,7 +148,7 @@ struct telem_args_get_batt_ext_info {
133
148
* We do not want to allow userspace to send arbitrary telemetry commands to
134
149
* the EC. Therefore we check to ensure that
135
150
* 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.
137
152
* 3. The request only contains the necessary data for the header and arguments.
138
153
*/
139
154
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,
146
161
147
162
switch (rq -> command ) {
148
163
case WILCO_EC_TELEM_GET_LOG :
149
- max_size += sizeof (struct telem_args_get_log );
164
+ max_size += sizeof (rq -> args . get_log );
150
165
break ;
151
166
case WILCO_EC_TELEM_GET_VERSION :
152
- max_size += sizeof (struct telem_args_get_version );
167
+ max_size += sizeof (rq -> args . get_version );
153
168
break ;
154
169
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 );
156
171
break ;
157
172
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 );
159
174
break ;
160
175
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 );
162
177
break ;
163
178
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 );
165
180
break ;
166
181
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 );
168
189
break ;
169
190
default :
170
191
return - EINVAL ;
@@ -250,6 +271,7 @@ static ssize_t telem_write(struct file *filp, const char __user *buf,
250
271
251
272
if (count > sizeof (sess_data -> request ))
252
273
return - EMSGSIZE ;
274
+ memset (& sess_data -> request , 0 , sizeof (sess_data -> request ));
253
275
if (copy_from_user (& sess_data -> request , buf , count ))
254
276
return - EFAULT ;
255
277
ret = check_telem_request (& sess_data -> request , count );
0 commit comments