Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp608030ybl; Fri, 23 Aug 2019 05:54:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPn6FMzMWiwzKkMFoOp7EhgAKpQZPyHp/tpNXIAKXE/jA0crXw3K8lWXbU3AWjiR4MQ2bs X-Received: by 2002:a17:90a:cd03:: with SMTP id d3mr5082628pju.117.1566564859787; Fri, 23 Aug 2019 05:54:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566564859; cv=none; d=google.com; s=arc-20160816; b=n+GdPmebo6L9u94RGPehzEI9WtxC679IjExuVD8NNs/VN8HhJGQ44XZGKvhzABtMkz DK3up/0A6jfKBBWbHAwjIKHeUU14SoKD5gffa21VaQUcVpWRElxQXQt49Yk5fRoo6R29 FPjSGXoxbCCnE7NrRRP+W+nbO3kIumnf62HPIXW6BZAZ/0fkDbxRDs6pnJRRHzvs/ttB Iwk+cCMRmkd5K2lh1riFqjp+HVrIkmKyLcuqPfgPJHN2EoFWTODAqvQKh249ll5bzlig SWkrHQ88vdaMOEEN08RhLBjD+Mtf/I7FdBf5GnGCRd1bw6OunO8idg5TcsHMmql0qw69 fyfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=UuWKFSzvEpg74qi2KyP9BM/RBYpRpZTScI16525W/sM=; b=gefcIpUGVy456T0T2QN9tmB/ASgQ5Haft1XWpjblTcVP6fc9qAlJXCEKuh62Fkc4yN q4fd0sGccYAs57PBlnJar/wNzH1d1H4D9I2Smpfhrd4L5ykFpHtr1623MufPMifbVOB8 zBswCgdk50eZLLZdb/4te18NF/O3mHe8r8x2R3zSzG5ynHWvKx8kuibBtSGYIxQUsvpP 2ISXBwbY/fVCVx779UB2dJVT4Al8wbfMS6xxnC2w2wYh7Id8IxrlFJovFEQ8MVAgIVs/ j6WsYolm8j0UnGCXv7x63Cz6AhruyP2qQJFtomMR9dtKY6KB1B8mXtTguV9ib5yPNg+a cobA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="QXr/IunZ"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z189si741768pgb.491.2019.08.23.05.54.03; Fri, 23 Aug 2019 05:54:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="QXr/IunZ"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392071AbfHVTn3 (ORCPT + 99 others); Thu, 22 Aug 2019 15:43:29 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:36602 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732235AbfHVTn3 (ORCPT ); Thu, 22 Aug 2019 15:43:29 -0400 Received: by mail-ot1-f67.google.com with SMTP id k18so6606068otr.3 for ; Thu, 22 Aug 2019 12:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UuWKFSzvEpg74qi2KyP9BM/RBYpRpZTScI16525W/sM=; b=QXr/IunZYtdgAcsEXj6VOEp8s+icCzq5F3829lta0k7zPYYwFza2YJg+Yyp+3E/fuI Ho2qPZwMbvm/pAGn6je2trSwuHBaszDSNl3le02HCvQg4BeZcOn+U+de07DCdLXnB8dn mxiWQFMxPzGAd0QZpQ+Xkg3jLXYu+9hpQb1Hw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UuWKFSzvEpg74qi2KyP9BM/RBYpRpZTScI16525W/sM=; b=RerYrXtBfZ0S1qG+nzGgOMKvlX67XK4EEXU8mZErPspWmIqvhCgYuuL5MJwmeWxoiR RxPi6aLM+aB3M2sOvxM5bKF8JrhaDccoc8JhY8J83fbRoShnDBxz34DgRYK8C4FMRV25 Td7NVBwyCBPr4hzFh9s5p8ux/iVwrbR4IYsn5Ke46Mrd0klXI0fziIUakFiH6JPKTW9R os5N5GzcZzPNN8gSS/4j/5PkjaDODnI5oZQ7VNkONeITMqENZ3pS7hOyBlRHRDnjWrgk F+kLIA4f4/2Q+gIs4YkECaTVJ4VFKT5lYb7MCaqgzHh98IWe3ct5X7byUR8AThrbDUhC xgsQ== X-Gm-Message-State: APjAAAWmaSaju09liu0PWGvTQ2AARrYPtzWRVLUyuwQN1VraM3VLbN5H lSvvVwMSNd6Aegqw8WF0is/nY/tc6Bc= X-Received: by 2002:a05:6830:1f10:: with SMTP id u16mr1102443otg.229.1566503007081; Thu, 22 Aug 2019 12:43:27 -0700 (PDT) Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com. [209.85.210.44]) by smtp.gmail.com with ESMTPSA id m7sm200738otm.5.2019.08.22.12.43.25 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Aug 2019 12:43:26 -0700 (PDT) Received: by mail-ot1-f44.google.com with SMTP id c34so6577851otb.7 for ; Thu, 22 Aug 2019 12:43:25 -0700 (PDT) X-Received: by 2002:a05:6830:158:: with SMTP id j24mr1106878otp.236.1566503005173; Thu, 22 Aug 2019 12:43:25 -0700 (PDT) MIME-Version: 1.0 References: <20190805202214.3408-1-ncrews@chromium.org> In-Reply-To: <20190805202214.3408-1-ncrews@chromium.org> From: Nick Crews Date: Thu, 22 Aug 2019 13:43:14 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] platform/chrome: wilco_ec: Add batt_ppid_info command to telemetry driver To: Enric Balletbo i Serra , Benson Leung Cc: linux-kernel , Duncan Laurie , Daniel Kurtz , Dmitry Torokhov , Simon Glass Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Friendly bump on this :) On Mon, Aug 5, 2019 at 2:22 PM Nick Crews wrote: > > 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 > --- > drivers/platform/chrome/wilco_ec/telemetry.c | 64 +++++++++++++------- > 1 file changed, 43 insertions(+), 21 deletions(-) > > diff --git a/drivers/platform/chrome/wilco_ec/telemetry.c b/drivers/platform/chrome/wilco_ec/telemetry.c > index 94cdc166c840..b9d03c33d8dc 100644 > --- a/drivers/platform/chrome/wilco_ec/telemetry.c > +++ b/drivers/platform/chrome/wilco_ec/telemetry.c > @@ -9,7 +9,7 @@ > * the OS sends a command to the EC via a write() to a char device, > * and can read the response with a read(). The write() request is > * verified by the driver to ensure that it is performing only one > - * of the whitelisted commands, and that no extraneous data is > + * of the allowlisted commands, and that no extraneous data is > * being transmitted to the EC. The response is passed directly > * back to the reader with no modification. > * > @@ -59,21 +59,10 @@ static DEFINE_IDA(telem_ida); > #define WILCO_EC_TELEM_GET_TEMP_INFO 0x95 > #define WILCO_EC_TELEM_GET_TEMP_READ 0x2C > #define WILCO_EC_TELEM_GET_BATT_EXT_INFO 0x07 > +#define WILCO_EC_TELEM_GET_BATT_PPID_INFO 0x8A > > #define TELEM_ARGS_SIZE_MAX 30 > > -/** > - * struct wilco_ec_telem_request - Telemetry command and arguments sent to EC. > - * @command: One of WILCO_EC_TELEM_GET_* command codes. > - * @reserved: Must be 0. > - * @args: The first N bytes are one of telem_args_get_* structs, the rest is 0. > - */ > -struct wilco_ec_telem_request { > - u8 command; > - u8 reserved; > - u8 args[TELEM_ARGS_SIZE_MAX]; > -} __packed; > - > /* > * The following telem_args_get_* structs are embedded within the |args| field > * of wilco_ec_telem_request. > @@ -122,6 +111,32 @@ struct telem_args_get_batt_ext_info { > u8 var_args[5]; > } __packed; > > +struct telem_args_get_batt_ppid_info { > + u8 always1; /* Should always be 1 */ > +} __packed; > + > +/** > + * struct wilco_ec_telem_request - Telemetry command and arguments sent to EC. > + * @command: One of WILCO_EC_TELEM_GET_* command codes. > + * @reserved: Must be 0. > + * @args: The first N bytes are one of telem_args_get_* structs, the rest is 0. > + */ > +struct wilco_ec_telem_request { > + u8 command; > + u8 reserved; > + union { > + u8 buf[TELEM_ARGS_SIZE_MAX]; > + struct telem_args_get_log get_log; > + struct telem_args_get_version get_version; > + struct telem_args_get_fan_info get_fan_info; > + struct telem_args_get_diag_info get_diag_info; > + struct telem_args_get_temp_info get_temp_info; > + struct telem_args_get_temp_read get_temp_read; > + struct telem_args_get_batt_ext_info get_batt_ext_info; > + struct telem_args_get_batt_ppid_info get_batt_ppid_info; > + } args; > +} __packed; > + > /** > * check_telem_request() - Ensure that a request from userspace is valid. > * @rq: Request buffer copied from userspace. > @@ -133,7 +148,7 @@ struct telem_args_get_batt_ext_info { > * We do not want to allow userspace to send arbitrary telemetry commands to > * the EC. Therefore we check to ensure that > * 1. The request follows the format of struct wilco_ec_telem_request. > - * 2. The supplied command code is one of the whitelisted commands. > + * 2. The supplied command code is one of the allowlisted commands. > * 3. The request only contains the necessary data for the header and arguments. > */ > 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, > > switch (rq->command) { > case WILCO_EC_TELEM_GET_LOG: > - max_size += sizeof(struct telem_args_get_log); > + max_size += sizeof(rq->args.get_log); > break; > case WILCO_EC_TELEM_GET_VERSION: > - max_size += sizeof(struct telem_args_get_version); > + max_size += sizeof(rq->args.get_version); > break; > case WILCO_EC_TELEM_GET_FAN_INFO: > - max_size += sizeof(struct telem_args_get_fan_info); > + max_size += sizeof(rq->args.get_fan_info); > break; > case WILCO_EC_TELEM_GET_DIAG_INFO: > - max_size += sizeof(struct telem_args_get_diag_info); > + max_size += sizeof(rq->args.get_diag_info); > break; > case WILCO_EC_TELEM_GET_TEMP_INFO: > - max_size += sizeof(struct telem_args_get_temp_info); > + max_size += sizeof(rq->args.get_temp_info); > break; > case WILCO_EC_TELEM_GET_TEMP_READ: > - max_size += sizeof(struct telem_args_get_temp_read); > + max_size += sizeof(rq->args.get_temp_read); > break; > case WILCO_EC_TELEM_GET_BATT_EXT_INFO: > - max_size += sizeof(struct telem_args_get_batt_ext_info); > + max_size += sizeof(rq->args.get_batt_ext_info); > + break; > + case WILCO_EC_TELEM_GET_BATT_PPID_INFO: > + if (rq->args.get_batt_ppid_info.always1 != 1) > + return -EINVAL; > + > + max_size += sizeof(rq->args.get_batt_ppid_info); > break; > default: > return -EINVAL; > @@ -250,6 +271,7 @@ static ssize_t telem_write(struct file *filp, const char __user *buf, > > if (count > sizeof(sess_data->request)) > return -EMSGSIZE; > + memset(&sess_data->request, 0, sizeof(sess_data->request)); > if (copy_from_user(&sess_data->request, buf, count)) > return -EFAULT; > ret = check_telem_request(&sess_data->request, count); > -- > 2.20.1 >