Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1786703pxb; Fri, 24 Sep 2021 11:49:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPwA+3mPgIixU/+h5DRVGhA6H5CiPbSxGXl4AwPgJFvoMcsG56jdhp++dlfCPV19lyhTtu X-Received: by 2002:a02:22cf:: with SMTP id o198mr10700831jao.37.1632509382922; Fri, 24 Sep 2021 11:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632509382; cv=none; d=google.com; s=arc-20160816; b=sRe3+03rtD1VVbCHwKzBuWQEDRCUndpFSIY8cQgp6lbpRC6XLHTHrifsxvD11234B3 sy0O97dJygSsjC+xiYgJZGnGKj6N7i9bIosB02WPKT2iGfxZUXKgQJUJVX/OrbQdVhaE N+TIncCtpmdkJiY57+IB173+QeNdEaPAhZDEWcLAzYl/jeeChvMbfWDkNMA1ozkmgAJm AfgxBBc2xikiuOJEEYfvZGfnMk4gyVlWnKmplemV7dxssOcVh0YAoguoAcSTGfbeLgIc FrLotKSlMjvCFLEysVFADmYCoEMxzhZlRFNuU0ZOsuWJSkpFgqWYzAulcalbwAHNYBwN FJDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UkETMOuLl480c9zjNJ0XcpDGuAy70AYSfappSMu0GV0=; b=ShE+F0kafK+8iX1crC7tKrI3bI+SPl00C0BtVTyBxWdMLkFHlaPpnotJ6I78AmV+dI fUC2J4BH4+Fh8pfnbt3BqM110F0UcY10Prwi4g88kXMK5G4FsSVtiFhw3ER3neJFX41V om7+T2+Whc2PRoAAPRig9/Ct5Fpu6M5Tt9nIxnHWRpKWb1EIv4mo7RzLDkr1ENRhLRTk ueS1uMwWm2al+31VbfNujhNmoVi3IDuKQq27VNv+Q52DQFq27MqRt5xSyD9p3IrRYns8 xVdU7jOy2FK58gAONlJMUBpjjJ4cAn1CLglE4RB8YSsajFgaUDQiohUKGAL0Hswo0Cnd gycQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q1ugftOi; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p31si14405095jac.95.2021.09.24.11.49.31; Fri, 24 Sep 2021 11:49:42 -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=@linuxfoundation.org header.s=korg header.b=Q1ugftOi; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345323AbhIXNPr (ORCPT + 99 others); Fri, 24 Sep 2021 09:15:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:38878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346675AbhIXNKO (ORCPT ); Fri, 24 Sep 2021 09:10:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5A718613A6; Fri, 24 Sep 2021 12:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632488287; bh=v/vqUdqTSUnR96EXa4I9dB+riotHyEVMBExY2ds6+Jo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q1ugftOiOPcW0piHV60VX0vy+SHnddAyi5TfdHMTNQqharGpPRuKJaDUqfLcmZmvC QFz7vay6YPLqkGbwQM4mDkCA/iy6ZYl0zBs8Rea3e7v1anH5W8627S4+xAz88bV8Ap gPQu6LgZcVYgjn7CheDko0B8R/wgJULQC70tccmw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ofir Bitton , Oded Gabbay , Sasha Levin Subject: [PATCH 5.10 55/63] habanalabs: add validity check for event ID received from F/W Date: Fri, 24 Sep 2021 14:44:55 +0200 Message-Id: <20210924124336.161503743@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210924124334.228235870@linuxfoundation.org> References: <20210924124334.228235870@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ofir Bitton [ Upstream commit a6c849012b0f51c674f52384bd9a4f3dc0a33c31 ] Currently there is no validity check for event ID received from F/W, Thus exposing driver to memory overrun. Signed-off-by: Ofir Bitton Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay Signed-off-by: Sasha Levin --- drivers/misc/habanalabs/gaudi/gaudi.c | 6 ++++++ drivers/misc/habanalabs/goya/goya.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/misc/habanalabs/gaudi/gaudi.c b/drivers/misc/habanalabs/gaudi/gaudi.c index 37edd663603f..ebac53a73bd1 100644 --- a/drivers/misc/habanalabs/gaudi/gaudi.c +++ b/drivers/misc/habanalabs/gaudi/gaudi.c @@ -5723,6 +5723,12 @@ static void gaudi_handle_eqe(struct hl_device *hdev, u8 cause; bool reset_required; + if (event_type >= GAUDI_EVENT_SIZE) { + dev_err(hdev->dev, "Event type %u exceeds maximum of %u", + event_type, GAUDI_EVENT_SIZE - 1); + return; + } + gaudi->events_stat[event_type]++; gaudi->events_stat_aggregate[event_type]++; diff --git a/drivers/misc/habanalabs/goya/goya.c b/drivers/misc/habanalabs/goya/goya.c index 5b5d6275c249..c8023b4428c5 100644 --- a/drivers/misc/habanalabs/goya/goya.c +++ b/drivers/misc/habanalabs/goya/goya.c @@ -4623,6 +4623,12 @@ void goya_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry) >> EQ_CTL_EVENT_TYPE_SHIFT); struct goya_device *goya = hdev->asic_specific; + if (event_type >= GOYA_ASYNC_EVENT_ID_SIZE) { + dev_err(hdev->dev, "Event type %u exceeds maximum of %u", + event_type, GOYA_ASYNC_EVENT_ID_SIZE - 1); + return; + } + goya->events_stat[event_type]++; goya->events_stat_aggregate[event_type]++; -- 2.33.0