Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 956C6C4332F for ; Sun, 11 Dec 2022 13:07:49 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 31B308539F; Sun, 11 Dec 2022 14:07:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Qisn7IdH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7A63D8539B; Sun, 11 Dec 2022 14:07:05 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BBBDD852C4 for ; Sun, 11 Dec 2022 14:06:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=jitloonl@ecsmtp.png.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670764017; x=1702300017; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5aVd661QCiB3XFtdxODsZNKUt5pua3ryfnkv5kgGryk=; b=Qisn7IdHTb3uxUtJRMSm+GYNEmLfJA6k4mt3FXnfVTXqBhgrt0MU8XXI /VPexSETw4oWLzooEiP53zgJQyliFeybLMV+WbQMCZUP2s+62Hq/5ZchJ Q3LWjxYzBsIg4SUmL5t9OqMnoNQpnWoQD8KkEGfpt1Ym+lF/HlfEazwej KjZAb1nk8/Amt/WmVE60aLdBXWhjonl8XDv4UJq/6UyiiRCRxfGWnRwmK kHRgQIXWeKDau4ZuK/CDD/wT3G5286rYAMKx0TX6Yr7fNn3iLyXaOXVdu iZuvredLkrFzqDJDgk+b8ssVjBanN6tM6Hx0u4dEatnqWU7di/DjPkGia g==; X-IronPort-AV: E=McAfee;i="6500,9779,10557"; a="316394360" X-IronPort-AV: E=Sophos;i="5.96,236,1665471600"; d="scan'208";a="316394360" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2022 05:06:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10557"; a="678625520" X-IronPort-AV: E=Sophos;i="5.96,236,1665471600"; d="scan'208";a="678625520" Received: from pglmail07.png.intel.com ([10.221.193.207]) by orsmga008.jf.intel.com with ESMTP; 11 Dec 2022 05:06:52 -0800 Received: from localhost (pgli0028.png.intel.com [10.221.84.177]) by pglmail07.png.intel.com (Postfix) with ESMTP id E9007189FC; Sun, 11 Dec 2022 21:06:47 +0800 (+08) Received: by localhost (Postfix, from userid 12048045) id E60CCE0095A; Sun, 11 Dec 2022 21:06:47 +0800 (+08) From: Jit Loon Lim To: u-boot@lists.denx.de Cc: Jagan Teki , Vignesh R , Marek , Simon , Tien Fong , Kok Kiang , Siew Chin , Sin Hui , Raaj , Dinesh , Boon Khai , Alif , Teik Heng , Hazim , Jit Loon Lim , Sieu Mun Tang Subject: [PATCH 6/6] arm: socfpga: Enhance checking on potential overwrite Date: Sun, 11 Dec 2022 21:06:44 +0800 Message-Id: <20221211130644.24832-6-jit.loon.lim@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20221211130644.24832-1-jit.loon.lim@intel.com> References: <20221211130644.24832-1-jit.loon.lim@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Tien Fong Chee Each register 4 bytes write, there is a potential that user setting an invalid offset which is less than block size, but overflow the block size when writing the register. This patch prevents this overwrite issue by checking earlier before starting any register write. Signed-off-by: Tien Fong Chee Signed-off-by: Jit Loon Lim --- drivers/misc/socfpga_secreg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/misc/socfpga_secreg.c b/drivers/misc/socfpga_secreg.c index a4b297e7f1..0ea30c254b 100644 --- a/drivers/misc/socfpga_secreg.c +++ b/drivers/misc/socfpga_secreg.c @@ -8,6 +8,7 @@ #include #include #include +#include static int socfpga_secreg_probe(struct udevice *dev) { @@ -53,10 +54,10 @@ static int socfpga_secreg_probe(struct udevice *dev) debug("%s(intel,offset-settings 0x%llx : 0x%llx)\n", __func__, offset, val); - if (blk_sz <= offset) { - printf("%s: Overflow as offset 0x%llx", + if (blk_sz < offset + SZ_4) { + printf("%s: Overflow as offset 0x%llx or reg", __func__, offset); - printf(" is larger than block size 0x%x\n", + printf(" write is more than block size 0x%x\n", blk_sz); return -EINVAL; } -- 2.26.2