Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp715675rdb; Fri, 2 Feb 2024 01:29:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0141xWHzaHNoJbnMdou+/6xscCreIsLcgc8yIHQHwrK4JtO6yaC/f2E3XK4RVsjc5aT39 X-Received: by 2002:a05:6a20:9594:b0:19e:4eb9:ef74 with SMTP id iu20-20020a056a20959400b0019e4eb9ef74mr1108566pzb.14.1706866175330; Fri, 02 Feb 2024 01:29:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706866175; cv=pass; d=google.com; s=arc-20160816; b=ew/pwYEIVcxW6qDSXiN1hzzRyrY/h3cxxzlWvPZbFcmldJL/4iax4BOnWpvsPZkzIt 8c79piGucrU1jdaWIMzaIetxWAbev6goSo6qBoltl38gbe64knK9uRcEoOXfrjMgqwoc rPENWAOg0avRaBVJzp/NRisgl/mmzR/D00bYNB/mpSnmLpzwcezjhKuI0vOcAFh2a4s6 DCnbhrnxhyV58DuqueeJRARY8hEgXU5+NCiKfuAPnr0CD5jRNZLfcVI2HIGwGIeZOQuA 8tym+FoK/zA5SrZi/v+ccZroUmvld4hIC9xkhfGB/UDcfT1q2uybZaImSPkOA2sEuItH 8ElQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=l0m/Gjp7SDRbDsYlkSWeJqSGW2Lh0YbHKLO2XoJqFfE=; fh=hvsAZ4pd1mEs+REuTmlKj/E3DHXhcnveYRw7jpYBGh0=; b=GSbU63FM6EF26yy2K54/4iZi1x1goGnb8BHodoApmNb2aUlP/yxmxqY2YcTeJSFr11 PVZLLk+LhgBssHEjgrvNXYD/et0shWkkYqkAfif+D3qLMFRlWG2pLCsfgVvCnthha3Kk 5XmRdvnYhn7adEDVnoYnyXsKYnsjcbo6s/N0xjweauggXsoK14/bnx1P4FJ7Xxt84ulf nFqr6LDjB1IM2Xhf53kU0S3ByFNTvFN/r5tMUVr7VSf/Mzh+YlhuXmuSfHg6ulbUl2cX 6Bw0WHrxGnhTKm/dtxfyqEc19HWRfzJoJZzKeEs7TGQJ2+DvZRQJI6gI25Pw4wJPiihk Zyvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="e1vluO/7"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49554-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49554-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCXdVGtXUVAcbg95nJ3H2KNZ0EfRpSrH8VNfDQLq2EK5BdFh87RSf3L6C7xFpuIZPpCIQA/vDD00yNvmN3KZfguMXE3nvyohSRAX16bwLg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o3-20020a056a001b4300b006d9bee251f7si1239722pfv.242.2024.02.02.01.29.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:29:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49554-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="e1vluO/7"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49554-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49554-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 493AE28F32C for ; Fri, 2 Feb 2024 09:22:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E15C78B7C; Fri, 2 Feb 2024 09:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="e1vluO/7" 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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; -- 2.34.1