Received: by 10.213.65.68 with SMTP id h4csp589841imn; Tue, 13 Mar 2018 14:08:17 -0700 (PDT) X-Google-Smtp-Source: AG47ELt6pQsKKkGrnSdOww46Kve+Pu60neda0XAfbmAqaTj9oTfV5jtEr2h3FQztisUNSA7O4NtD X-Received: by 10.98.32.28 with SMTP id g28mr1940409pfg.182.1520975297300; Tue, 13 Mar 2018 14:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520975297; cv=none; d=google.com; s=arc-20160816; b=uAbMRsmFklzpXCCoD/YzSaLIzJw+MqTbbnY1dHbdAipfIx43jTd5KHSsnLHpFZhfeO fasVO31fp5r7/xvkNo9AeE5MU3jKAy+roJfgEWaN27i6GSqzctbliQ/E2aXYCp+soM8g x2JS6r0V122CBDNBaSHjFSK+6UDU9geUFRRVTJlde+OUCxSdlIe+wC2QSzE+yip8q5vt yvtIqCqM3p7lSaOhXMNoJ1UUbK7xqeeRYP5IGaXl3CjfLUrSdeJym/qlXHQ1OYepmV/y NN2/FCnxpzi1pWsfkEyUyGB/Ot0M4Se4DzinxFMaQ+SjNPQZBX/7t0xXZwdW8UW0A3eH VGxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from:arc-authentication-results; bh=2T5VM2QFUK1khs6rg5NQmUgwcGE9xaYp1kB9Oi+p4qk=; b=XpbXl5y+HyOP8g/idzqHC7tgHcyaT7m79H8RPr506rjCE6o+9mMeAF03rwYKZ4fgNa hD1STLOZFFl4oNbi/EwucSIrTPJohuELxl7ZwgbQPpcyQKH8b0IeKO/b2nCvU4LFxhYR sYbDOAhCYm5FaFSCA+mACMLU0uE56bm6h7g1BSJ2s7Q6z1JeN7pX/7QodpemuP3y91qv VegByefCwD+sHbzb+HJYujW1S1jrEMlVYX1yuynBHXk80lvFgr1ofJprw8aSYnFOpgSr rZJUnSQqCnHVxsko3pk6E8ul3j0/3mp/qvN6+ZJjSWAhLqJOX/GkgnWbI6jYJfmgXVzY 5sLQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 34-v6si716366plp.252.2018.03.13.14.08.02; Tue, 13 Mar 2018 14:08:17 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932635AbeCMVGj (ORCPT + 99 others); Tue, 13 Mar 2018 17:06:39 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:46158 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751903AbeCMVGg (ORCPT ); Tue, 13 Mar 2018 17:06:36 -0400 Received: by vps-vb.mhejs.net with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1evr7y-0004SG-JX; Tue, 13 Mar 2018 22:06:34 +0100 From: "Maciej S. Szmigiero" Subject: [PATCH v3 3/9] x86/microcode/AMD: install_equiv_cpu_table() should not return (signed) int To: Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org References: Message-ID: Date: Tue, 13 Mar 2018 22:06:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=iso-8859-2 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The maximum possible value returned by install_equiv_cpu_table() is UINT_MAX + CONTAINER_HDR_SZ (on a 64-bit kernel). This is more than (signed) int type currently returned by this function can hold so this function will need to return a size_t instead. The individual (negative) error codes returned by this function are of no use anyway, since they are all normalized to UCODE_ERROR by its caller (__load_microcode_amd()). Signed-off-by: Maciej S. Szmigiero --- arch/x86/kernel/cpu/microcode/amd.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index ac06e2819f26..d20c327c960b 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -547,37 +547,38 @@ static enum ucode_state apply_microcode_amd(int cpu) return UCODE_UPDATED; } -static int install_equiv_cpu_table(const u8 *buf, size_t buf_size) +static size_t install_equiv_cpu_table(const u8 *buf, size_t buf_size) { unsigned int *ibuf = (unsigned int *)buf; - unsigned int type, size; + unsigned int type; + size_t size; if (buf_size < CONTAINER_HDR_SZ) { pr_err("no container header\n"); - return -EINVAL; + return 0; } type = ibuf[1]; if (type != UCODE_EQUIV_CPU_TABLE_TYPE) { pr_err("invalid type field in container file section header\n"); - return -EINVAL; + return 0; } size = ibuf[2]; if (size < sizeof(struct equiv_cpu_entry)) { pr_err("equivalent CPU table too short\n"); - return -EINVAL; + return 0; } if (buf_size - CONTAINER_HDR_SZ < size) { pr_err("equivalent CPU table truncated\n"); - return -EINVAL; + return 0; } equiv_cpu_table = vmalloc(size); if (!equiv_cpu_table) { pr_err("failed to allocate equivalent CPU table\n"); - return -ENOMEM; + return 0; } memcpy(equiv_cpu_table, buf + CONTAINER_HDR_SZ, size); @@ -672,13 +673,13 @@ static enum ucode_state __load_microcode_amd(u8 family, const u8 *data, size_t size) { enum ucode_state ret = UCODE_ERROR; - unsigned int leftover; + size_t leftover; u8 *fw = (u8 *)data; int crnt_size = 0; - int offset; + size_t offset; offset = install_equiv_cpu_table(data, size); - if (offset < 0) { + if (!offset) { pr_err("failed to create equivalent cpu table\n"); return ret; }