Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1205399pxk; Mon, 31 Aug 2020 12:43:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTsX9YF7LvmkO9LZsxisC3z6xMCvE8t52Q9ZSJNCcuyK/CsqCj2eV+2W3a/z+lJMYmE7Ep X-Received: by 2002:a17:906:d187:: with SMTP id c7mr2519220ejz.196.1598903006094; Mon, 31 Aug 2020 12:43:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598903006; cv=none; d=google.com; s=arc-20160816; b=wnMQ9bOTSpXGWzHgowIo9lUdUZPbHscRg9QD7Mgu8BG00c6g3ZF6S2E+veRFUBbYBP 62v57E/7mn+DLGELncb0AKKJOmhSKa6lhwNfF5bU4xQu6/UJ81mdFNB9tCVA1Ezz5Z5S mTvdFPhqmjNeVuGE13ghxIqHr9yx1PRbnpBU/xAU1o+oEuLqRDKlp2ioBuelcp8qgSO/ XrnVXt0IZyKcFJQAzUNziyI95ixH8ljdaAY+3uw2A4o9tBnLWlTvK5hl8+yXOzF6nK13 rQ2fQyAODl4edpeoV2wSF8oor2I0kyjYZBdp9+Y/REpNT31uXY3RR6ytUHJ8aJopAXBk PVHQ== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LE6nYgWXAECuizmiV/Tn+Xvj8R0kozRS/KctqOc2qLM=; b=TA4aPJxzCGKT1CQTbSHe1u2JXpMuUK6ZkEv4qDzU/HYnYO/B6SiKlUxZoTHwZwaYnR JPRRc03rtykbk/HR4ayqdA2wLbBbR/CvIR2X+MFnHyuiLFZAJg8i1JBnMQihMl7StxAa vS/YeYBU7olbMLvJAkZVtN0wNk5inilYT2Nh6vO7+09azdDxhPpOcf1McfPNVYs5n+xJ hFLmgRWilbQJ9O3aLb9bPQT+mIVhYQCHqf2rVFTdoYVfdN3Z7+4F3+7tNH97kFcA0JSE dagN2Bl3BafX7LXJKzgp00+ch8tfHq3tgi8aQWeBxCWpUcvdL+c1gW6EkhOp5k6OarRf 5sfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qvxlaz7B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay11si2484051edb.517.2020.08.31.12.43.02; Mon, 31 Aug 2020 12:43:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qvxlaz7B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729407AbgHaPjk (ORCPT + 99 others); Mon, 31 Aug 2020 11:39:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:39200 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728526AbgHaPaD (ORCPT ); Mon, 31 Aug 2020 11:30:03 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E872A20936; Mon, 31 Aug 2020 15:30:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598887803; bh=9R4Lb8/rS3PyMG8TzFaJ1uD6D9wLNRMWS/lo3IlBBOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qvxlaz7BAWlaxRhzfvWKfRzZ7HrnaBKADCqKJKAWrHCNy4pHPEo1Sy91mQ4v0MW1F NQwi8y3rruVEuzmHsZ8QAxn2DIMFDUcbVUaapDX3rUkd7XgL9KLDA84/DntOYLhdkh 0mmgbgYqOoBzuKnamG5GoVL26w5kkMOqhDbLn+DU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ofir Bitton , Oded Gabbay , Sasha Levin Subject: [PATCH AUTOSEL 5.8 19/42] habanalabs: validate FW file size Date: Mon, 31 Aug 2020 11:29:11 -0400 Message-Id: <20200831152934.1023912-19-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200831152934.1023912-1-sashal@kernel.org> References: <20200831152934.1023912-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ofir Bitton [ Upstream commit bce382a8bb080ed5f2f3a06754526dc58b91cca2 ] We must validate FW size in order not to corrupt memory in case a malicious FW file will be present in system. Signed-off-by: Ofir Bitton Signed-off-by: Oded Gabbay Signed-off-by: Sasha Levin --- drivers/misc/habanalabs/firmware_if.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/misc/habanalabs/firmware_if.c b/drivers/misc/habanalabs/firmware_if.c index d27841cb5bcb3..345c228a7971e 100644 --- a/drivers/misc/habanalabs/firmware_if.c +++ b/drivers/misc/habanalabs/firmware_if.c @@ -13,6 +13,7 @@ #include #include +#define FW_FILE_MAX_SIZE 0x1400000 /* maximum size of 20MB */ /** * hl_fw_load_fw_to_device() - Load F/W code to device's memory. * @hdev: pointer to hl_device structure. @@ -45,6 +46,14 @@ int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name, dev_dbg(hdev->dev, "%s firmware size == %zu\n", fw_name, fw_size); + if (fw_size > FW_FILE_MAX_SIZE) { + dev_err(hdev->dev, + "FW file size %zu exceeds maximum of %u bytes\n", + fw_size, FW_FILE_MAX_SIZE); + rc = -EINVAL; + goto out; + } + fw_data = (const u64 *) fw->data; memcpy_toio(dst, fw_data, fw_size); -- 2.25.1