Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp70543ybd; Tue, 25 Jun 2019 16:45:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqzmVVMMc4wXxcyUDkpIelDu7PF5JuK+PxgF5aJohkh9bSKvjABgrUw9V61Z0XbJmkB3JVjU X-Received: by 2002:a17:902:a60d:: with SMTP id u13mr1503247plq.144.1561506332820; Tue, 25 Jun 2019 16:45:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561506332; cv=none; d=google.com; s=arc-20160816; b=WvrLqVNQnACBO8GWb4PsvNzGdbilLO2tKyq2+aw5/sbZE1mnv6ifmpMyDg28bQ+OqP FDoaU47cmghnU/ZFVsy8l/WXpOhU2jUk7jnbws3TN43nEPAjqy7nIJ/cMF8K+iPpqvcm zKf5ftfHID9teZOV98TgPt3EdnYqBKpTZpBkMDoH+fKlcS8ZKJkN9GnxLaJ9p/dJZ3kq oKvaGPzOlhu6KFErTNVe8y9xICfMkgsHmQ8E5u+CJFf77D5/o/RikVfLTwkKxH/8q7Pa F2JVBSEy97keyocakJRXo9dKrYXq6jWiqUpft+VgCOszy+Nn8tn+3hRN9aTmwqV0ZmIT HhaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:content-language:accept-language:message-id:date :thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=YCE0nLVIaBsXOvmvrCxtp1ladufAHFiyA27JjwI3k2A=; b=wYee5gENJixwaWY1ae86SRoBMVamFXVgULbqoMT+wqsHazZxDm4HJPSqesbRYyGKUC uLaynTX/dABMGsnVvDKH8F2seXU1q+PrR7xgf5WtzWSsmyeQaEUs89rK7rWnXN7Utbjr 9ONL3U65MYNrIz6Pa7uODqFY0WqxWyv9oa2xeCq2sihxPBMp8r4tAY9nbS1V8v+zPkNM OVlOku92ogSm7YYmYnHDKD1shRsUS497t/JXldV5KgPF9qfCi0IYVncWq+1sY+xy0xl7 fQi7+uzDNXWIdhz8FGWSV5lgVQp1E8oT2XW+KfQifHfofgh4nDkGj7k+xunugwucpy50 RnkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amdcloud-onmicrosoft-com header.b=v4uvmU5V; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bj12si1368712plb.378.2019.06.25.16.45.19; Tue, 25 Jun 2019 16:45:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=@amdcloud.onmicrosoft.com header.s=selector1-amdcloud-onmicrosoft-com header.b=v4uvmU5V; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726068AbfFYXpS (ORCPT + 99 others); Tue, 25 Jun 2019 19:45:18 -0400 Received: from mail-eopbgr740054.outbound.protection.outlook.com ([40.107.74.54]:11040 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725782AbfFYXpS (ORCPT ); Tue, 25 Jun 2019 19:45:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YCE0nLVIaBsXOvmvrCxtp1ladufAHFiyA27JjwI3k2A=; b=v4uvmU5Vh7hxbIT5zowEGHCEtuhEP1S+2jM4qDL9199kh3Xr6VIRlwI6RPRVZLAHUxlGxN3OXVnn/a2nk4bO5mXTMm3V2EpUHy5irwb1KfA2yscNJdyzsN0w0OSN2sqysYcZjbF2NqO3uvTHjPfPbkzqyjPN0pcGjeHDx62lGg0= Received: from DM5PR12MB1449.namprd12.prod.outlook.com (10.172.40.14) by DM5PR12MB1818.namprd12.prod.outlook.com (10.175.92.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2008.13; Tue, 25 Jun 2019 23:44:30 +0000 Received: from DM5PR12MB1449.namprd12.prod.outlook.com ([fe80::180c:ff0c:37e6:a482]) by DM5PR12MB1449.namprd12.prod.outlook.com ([fe80::180c:ff0c:37e6:a482%10]) with mapi id 15.20.2008.017; Tue, 25 Jun 2019 23:44:30 +0000 From: "Hook, Gary" To: "linux-crypto@vger.kernel.org" CC: "Lendacky, Thomas" , "herbert@gondor.apana.org.au" , "davem@davemloft.net" Subject: [PATCH] crypto: ccp - Validate the the error value used to index error messages Thread-Topic: [PATCH] crypto: ccp - Validate the the error value used to index error messages Thread-Index: AQHVK6/uRkTOBtmb8EK2WNLQif3aHQ== Date: Tue, 25 Jun 2019 23:44:30 +0000 Message-ID: <156150626887.22604.14664865428727189837.stgit@taos> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN2PR01CA0007.prod.exchangelabs.com (2603:10b6:804:2::17) To DM5PR12MB1449.namprd12.prod.outlook.com (2603:10b6:4:10::14) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a1f80211-ff25-4fd1-1e81-08d6f9c71140 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:DM5PR12MB1818; x-ms-traffictypediagnostic: DM5PR12MB1818: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:612; x-forefront-prvs: 0079056367 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(7916004)(376002)(136003)(39860400002)(366004)(396003)(346002)(199004)(189003)(25786009)(99286004)(33716001)(81166006)(81156014)(5660300002)(8936002)(53936002)(4326008)(7736002)(66066001)(9686003)(6116002)(6512007)(3846002)(6486002)(305945005)(8676002)(6436002)(15650500001)(6916009)(2501003)(66946007)(256004)(73956011)(478600001)(5640700003)(14454004)(68736007)(2906002)(316002)(64756008)(102836004)(386003)(6506007)(72206003)(66476007)(186003)(71200400001)(52116002)(54906003)(103116003)(476003)(2351001)(71190400001)(14444005)(486006)(66556008)(66446008)(26005)(86362001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1818;H:DM5PR12MB1449.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: kkGj3ogB31zKN2sv9j1uwrXAvDNGeiAS2/S2H5FzGsLKs8vLPPzRDeqwZFSZV+oMrS/NGw+QQz9TeyNwJ0DPMy6CcOKWDiSK0KbJOAKLgcpcPw5Q3Lu9EIM2yes1sEf1GoQ2iO97o5AIuS8KTfuqCy5Q+Lf5H+xvNnIiTtGJhsDZigi5XT/1C7mrv65zkuCZnd9ov6pehuGfCGZTjOtL8CqPCN+3wlIwxPTcwAdZ3LMj2PAKvhek/ENHrY9HYRJU+6BmtjW2wB84vlF7PgMGigu2hV5NMA2xNfDraFDTzskCMuh5SwnxtfwgYRS+AqJqMioVjsybimOPVtrOrjOodJFuX4APtbuzpcavg2unBB7BYeJ0yIuq5pwxKebIiXMgv/+151kX+2Nybxp8tLgrhR6qyn3uVQAKAdAUKivpW1Y= Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1f80211-ff25-4fd1-1e81-08d6f9c71140 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Jun 2019 23:44:30.5619 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ghook@amd.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1818 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The error code read from the queue status register is only 6 bits wide, but we need to verify its value is within range before indexing the error messages. Also, fill out the array with all possible entries so that any unexpected error codes are reported as "unknown". Fixes: 81422badb3907 ("crypto: ccp - Make syslog errors human-readable") Reported-by: Cfir Cohen Signed-off-by: Gary R Hook --- drivers/crypto/ccp/ccp-dev.c | 94 ++++++++++++++++++++++----------------= ---- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c index 1b5035d56288..c6853e17cebb 100644 --- a/drivers/crypto/ccp/ccp-dev.c +++ b/drivers/crypto/ccp/ccp-dev.c @@ -35,56 +35,62 @@ struct ccp_tasklet_data { }; =20 /* Human-readable error strings */ +#define CCP_MAX_ERROR_CODE 64 static char *ccp_error_codes[] =3D { "", - "ERR 01: ILLEGAL_ENGINE", - "ERR 02: ILLEGAL_KEY_ID", - "ERR 03: ILLEGAL_FUNCTION_TYPE", - "ERR 04: ILLEGAL_FUNCTION_MODE", - "ERR 05: ILLEGAL_FUNCTION_ENCRYPT", - "ERR 06: ILLEGAL_FUNCTION_SIZE", - "ERR 07: Zlib_MISSING_INIT_EOM", - "ERR 08: ILLEGAL_FUNCTION_RSVD", - "ERR 09: ILLEGAL_BUFFER_LENGTH", - "ERR 10: VLSB_FAULT", - "ERR 11: ILLEGAL_MEM_ADDR", - "ERR 12: ILLEGAL_MEM_SEL", - "ERR 13: ILLEGAL_CONTEXT_ID", - "ERR 14: ILLEGAL_KEY_ADDR", - "ERR 15: 0xF Reserved", - "ERR 16: Zlib_ILLEGAL_MULTI_QUEUE", - "ERR 17: Zlib_ILLEGAL_JOBID_CHANGE", - "ERR 18: CMD_TIMEOUT", - "ERR 19: IDMA0_AXI_SLVERR", - "ERR 20: IDMA0_AXI_DECERR", - "ERR 21: 0x15 Reserved", - "ERR 22: IDMA1_AXI_SLAVE_FAULT", - "ERR 23: IDMA1_AIXI_DECERR", - "ERR 24: 0x18 Reserved", - "ERR 25: ZLIBVHB_AXI_SLVERR", - "ERR 26: ZLIBVHB_AXI_DECERR", - "ERR 27: 0x1B Reserved", - "ERR 27: ZLIB_UNEXPECTED_EOM", - "ERR 27: ZLIB_EXTRA_DATA", - "ERR 30: ZLIB_BTYPE", - "ERR 31: ZLIB_UNDEFINED_SYMBOL", - "ERR 32: ZLIB_UNDEFINED_DISTANCE_S", - "ERR 33: ZLIB_CODE_LENGTH_SYMBOL", - "ERR 34: ZLIB _VHB_ILLEGAL_FETCH", - "ERR 35: ZLIB_UNCOMPRESSED_LEN", - "ERR 36: ZLIB_LIMIT_REACHED", - "ERR 37: ZLIB_CHECKSUM_MISMATCH0", - "ERR 38: ODMA0_AXI_SLVERR", - "ERR 39: ODMA0_AXI_DECERR", - "ERR 40: 0x28 Reserved", - "ERR 41: ODMA1_AXI_SLVERR", - "ERR 42: ODMA1_AXI_DECERR", - "ERR 43: LSB_PARITY_ERR", + "ILLEGAL_ENGINE", + "ILLEGAL_KEY_ID", + "ILLEGAL_FUNCTION_TYPE", + "ILLEGAL_FUNCTION_MODE", + "ILLEGAL_FUNCTION_ENCRYPT", + "ILLEGAL_FUNCTION_SIZE", + "Zlib_MISSING_INIT_EOM", + "ILLEGAL_FUNCTION_RSVD", + "ILLEGAL_BUFFER_LENGTH", + "VLSB_FAULT", + "ILLEGAL_MEM_ADDR", + "ILLEGAL_MEM_SEL", + "ILLEGAL_CONTEXT_ID", + "ILLEGAL_KEY_ADDR", + "0xF Reserved", + "Zlib_ILLEGAL_MULTI_QUEUE", + "Zlib_ILLEGAL_JOBID_CHANGE", + "CMD_TIMEOUT", + "IDMA0_AXI_SLVERR", + "IDMA0_AXI_DECERR", + "0x15 Reserved", + "IDMA1_AXI_SLAVE_FAULT", + "IDMA1_AIXI_DECERR", + "0x18 Reserved", + "ZLIBVHB_AXI_SLVERR", + "ZLIBVHB_AXI_DECERR", + "0x1B Reserved", + "ZLIB_UNEXPECTED_EOM", + "ZLIB_EXTRA_DATA", + "ZLIB_BTYPE", + "ZLIB_UNDEFINED_SYMBOL", + "ZLIB_UNDEFINED_DISTANCE_S", + "ZLIB_CODE_LENGTH_SYMBOL", + "ZLIB _VHB_ILLEGAL_FETCH", + "ZLIB_UNCOMPRESSED_LEN", + "ZLIB_LIMIT_REACHED", + "ZLIB_CHECKSUM_MISMATCH0", + "ODMA0_AXI_SLVERR", + "ODMA0_AXI_DECERR", + "0x28 Reserved", + "ODMA1_AXI_SLVERR", + "ODMA1_AXI_DECERR", }; =20 void ccp_log_error(struct ccp_device *d, int e) { - dev_err(d->dev, "CCP error: %s (0x%x)\n", ccp_error_codes[e], e); + if (WARN_ON((e < 0) || (e >=3D CCP_MAX_ERROR_CODE))) + return; + + if (e < ARRAY_SIZE(ccp_error_codes)) + dev_err(d->dev, "CCP error %d: %s\n", e, ccp_error_codes[e]); + else + dev_err(d->dev, "CCP error %d: Unknown Error\n", e); } =20 /* List of CCPs, CCP count, read-write access lock, and access functions