From patchwork Fri Jan 18 01:13:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Gupta X-Patchwork-Id: 10769269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B7C0C139A for ; Fri, 18 Jan 2019 01:13:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A22142EBB0 for ; Fri, 18 Jan 2019 01:13:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9366C2EBC5; Fri, 18 Jan 2019 01:13:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E8352EBB0 for ; Fri, 18 Jan 2019 01:13:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726398AbfARBN2 (ORCPT ); Thu, 17 Jan 2019 20:13:28 -0500 Received: from hqemgate16.nvidia.com ([216.228.121.65]:15002 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726182AbfARBN2 (ORCPT ); Thu, 17 Jan 2019 20:13:28 -0500 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 17 Jan 2019 17:12:56 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Thu, 17 Jan 2019 17:13:27 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Thu, 17 Jan 2019 17:13:27 -0800 Received: from ajayg.nvidia.com (172.17.174.172) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 18 Jan 2019 01:13:25 +0000 From: Ajay Gupta To: CC: , Ajay Gupta Subject: [PATCH 6/7] usb: typec: ucsi: add check for supported vendor Date: Thu, 17 Jan 2019 17:13:02 -0800 Message-ID: <20190118011302.16256-1-ajayg@nvidia.com> X-Mailer: git-send-email 2.17.1 X-NVConfidentiality: public MIME-Version: 1.0 X-Originating-IP: [172.17.174.172] X-ClientProxiedBy: DRBGMAIL101.nvidia.com (10.18.16.20) To HQMAIL101.nvidia.com (172.20.187.10) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1547773976; bh=7YHK99n5BUAVtCgkRbmhZXBMW1qr03ZOp07qOVlHk0M=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: X-NVConfidentiality:MIME-Version:X-Originating-IP: X-ClientProxiedBy:Content-Type; b=hPRAFZbtDeDJA6TAXDLpUnGn43PQ7BKSg/EQHsqNUzYcb9nS+GpEYp/QaVLIiq7Ax XDtt9y56k5By+qJkBa2Yq+kKb/Uz/nJz+RfvQHaQD33dVbQM+N39ZJOh4PeWThgk3H +jsehxtQlQ6DUyaI46lSdvXWbVQsaji9Dj6P3q1kJpdEvrHNHxr+FBL9j2GYAhIOoV SufZEVQwLyHyu+fTuOazoVlvTiZyQFNBfgnEy7nyH0UiIFd4jz40sNEmn8hB+gGBfb hSpxDMJ9WIKdECob4MUWwt2X4qb53URUFvNKSOBGrUhoWg4gVA7MxBBpJZWAOiPJEO QM2ow69THwxpQ== Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Added check to see the currently flashed or new firmware being flashed is from a supported vendor. Signed-off-by: Ajay Gupta --- drivers/usb/typec/ucsi/ucsi_ccg.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index 6069a9f60d1e..1aa6ede764b5 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -775,6 +775,30 @@ static int ccg_cmd_validate_fw(struct ucsi_ccg *uc, unsigned int fwid) return 0; } +static bool ccg_check_vendor_version(struct ucsi_ccg *uc, + struct version_format *app, + struct fw_config_table *fw_cfg) +{ + struct device *dev = uc->dev; + + /* Check if the fw build is for supported vendors. + * Add all supported vendors here. + */ + if (app->build != (('n' << 8) | 'v')) { + dev_info(dev, "current fw is not from supported vendor\n"); + return false; + } + + /* Check if the new fw build is for supported vendors + * Add all supported vendors here. + */ + if (fw_cfg->app.build != (('n' << 8) | 'v')) { + dev_info(dev, "new fw is not from supported vendor\n"); + return false; + } + return true; +} + static bool ccg_check_fw_version(struct ucsi_ccg *uc, const char *fw_name, struct version_format *app) { @@ -814,6 +838,9 @@ static bool ccg_check_fw_version(struct ucsi_ccg *uc, const char *fw_name, dev_dbg(dev, "compare current %08x and new version %08x\n", cur_version, new_version); + if (!ccg_check_vendor_version(uc, app, &fw_cfg)) + goto not_supported_version; + if (new_version > cur_version) { dev_dbg(dev, "new firmware file version is later\n"); is_later = true; @@ -821,6 +848,7 @@ static bool ccg_check_fw_version(struct ucsi_ccg *uc, const char *fw_name, dev_dbg(dev, "new firmware file version is same or earlier\n"); } +not_supported_version: not_signed_fw: release_firmware(fw); return is_later;