From patchwork Fri Feb 2 09:21:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 13542473 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FB5577F2F; Fri, 2 Feb 2024 09:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865720; cv=none; b=hpHF57H6uHFZn62sA2w0PiP7gDeILyvNwlsrkUBHNPy+UcKFwt/HvTeND1SJVNNrNpM6IrxbnUM1ii4rLax4DUDhi9Lg6e/u8LLfZDkyh4Ql6XTH104ii6pOKymQQCmAg54gsnYlzIWZq1uOGTi2gA8qoBXUOWfIoUV/loTycNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865720; c=relaxed/simple; bh=5xEYbhycCuhMZxcJFYEmbEaTkihqPSlxlZTL6ZsEoEQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gyqBQa+ndr7rJga0rzlUdlKySk20IphykEYHZZnMBgGvwMc2Z4BEbGBYmxzPJ2N0d8CaIIs7+Ed44Xs7IjnSglSsb0kmGfPsajS3WwY22RvvMKDcGZYSqs7efsq1wPBsrMOLDf2J+rlp3NkHVvMSi6gUfaciK/TM0lVVIBSKZHc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=e1vluO/7; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="e1vluO/7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865719; x=1738401719; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5xEYbhycCuhMZxcJFYEmbEaTkihqPSlxlZTL6ZsEoEQ=; b=e1vluO/7IhLYa2JI6v+6uaUNaey8qJ2GBgCn/Nf4DGpzcA9b0fl296qa AQLVIgIodBmTDl4FWmlQRD+pIG0WpsKHlWm6oq5anpbDGDz11AhpAbMUf OuolOwo/ViI8TM/mFRKOJDj3uiAd/rHWFYyvx5qCZ639BFz0scjec3b5R FsiLwPaX2mA2xVoIEg2gulFSmCvAvTzgVJ9g+MHiN7JebFY5o55BzcyEh 3PKGFaTc1sguezIQSJ+0ja+XcjUXQO92MxYBktcAq60yOgtOewsrVYQjJ UgSP5UBP2Fh1YGPo5bZRL/eri88VUBMMqew2rHpkBu1L/Lj4Vr3NWjpVE A==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="11483041" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="11483041" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:21:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="4639679" Received: from wangnin3-mobl.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.177]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:21:55 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 01/11] hwmon: (coretemp) Fix out-of-bounds memory access Date: Fri, 2 Feb 2024 17:21:34 +0800 Message-Id: <20240202092144.71180-2-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202092144.71180-1-rui.zhang@intel.com> References: <20240202092144.71180-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fix a bug that pdata->cpu_map[] is set before out-of-bounds check. The problem might be triggered on systems with more than 128 cores per package. Fixes: 7108b80a542b ("hwmon/coretemp: Handle large core ID value") Signed-off-by: Zhang Rui Cc: --- drivers/hwmon/coretemp.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index ba82d1e79c13..e78c76919111 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -509,18 +509,14 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, if (pkg_flag) { attr_no = PKG_SYSFS_ATTR_NO; } else { - index = ida_alloc(&pdata->ida, GFP_KERNEL); + index = ida_alloc_max(&pdata->ida, NUM_REAL_CORES - 1, GFP_KERNEL); if (index < 0) return index; + pdata->cpu_map[index] = topology_core_id(cpu); attr_no = index + BASE_SYSFS_ATTR_NO; } - if (attr_no > MAX_CORE_DATA - 1) { - err = -ERANGE; - goto ida_free; - } - tdata = init_temp_data(cpu, pkg_flag); if (!tdata) { err = -ENOMEM;