Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp90960pxb; Wed, 1 Sep 2021 22:53:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8aowwO1kLUyVBrOl1E9Z1FM7nnQcIKSUsjJ50YlorbhTJu51uNv4hTKla0I//WA8BgRi5 X-Received: by 2002:a05:6e02:1054:: with SMTP id p20mr1072164ilj.159.1630561986393; Wed, 01 Sep 2021 22:53:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630561986; cv=none; d=google.com; s=arc-20160816; b=cAuyRDRfCl3vTlOSlhv19tcOYSZ6BeI31Q5Wf7DZi5Uf/FER8V2IgVmdhLOkQ3bh8N EBELpLjolralDmbNeoh1bo2gl97xmRw0/lOexgPJpSDZxKO0E7k7ZLw4eGSJEB2L4rni +V4ySRV8hhDmQgJe/Vo1uVVhNcbAtFgDELXBET5r2Lrbaxxek612O0HaeCuuKZd5fv1j oL7xsFKnWGJzmrw/OWhdeLD5b6vR+DG/1XMCUFBjBf2TGKEGIXOPEvMrEm+UyTZ3DYB0 sjqYFIMDgu5581sjFKfh/CMeovgPsMzyjEI23kCXwnytrgGgg7klrrNVf3UB9yEzbF4Q 8Iow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=MimgWrFV0sUGLhnEsIBMESbKRrldo12pmrtSlQ0J5fA=; b=D4N8HaaxaIkwyXW2MN9Tgx5o/LnEVQgWBtAhVTj9irrPvb56UDIRMOmC8tBUd0dZ4Z 3vOIskmuN3pMTkhgNElnmPzK0hUheQ2a2j/HDc9pJTHCf8KHIS4DqQyAq0UZZi/6W+Ga 2WCJICqI0cak58mTutymOadIMtXGcvxK4/PLiyQpPUMKAdouCdxjQAqmKIvD4LeEM7+8 RZViOYq53YQy7mdWxm7M79+D9k7uHWGsM7XhjCze4a5dkW01mLkBoyVBnQcTXxbWjIrY BrwcZ2+6lLMEylOLG7ztfLdjc2ZZX0xQc7SxD0V89REseRYTPdzJiDkw6qB4+C6eCbBc E0+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si922171ion.34.2021.09.01.22.52.50; Wed, 01 Sep 2021 22:53:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233233AbhIBFxn (ORCPT + 99 others); Thu, 2 Sep 2021 01:53:43 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:47678 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231831AbhIBFxm (ORCPT ); Thu, 2 Sep 2021 01:53:42 -0400 X-UUID: 829f045f5a7c4f3a9089fb1c2a6bf45d-20210902 X-UUID: 829f045f5a7c4f3a9089fb1c2a6bf45d-20210902 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 309807063; Thu, 02 Sep 2021 13:52:42 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Sep 2021 13:52:40 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Sep 2021 13:52:40 +0800 From: Ryder Lee To: Felix Fietkau CC: Lorenzo Bianconi , Shayne Chen , Evelyn Tsai , , , Ben Greear , Ryder Lee Subject: [PATCH v6 1/2] mt76: mt7915: fix hwmon temp sensor mem use-after-free Date: Thu, 2 Sep 2021 13:52:03 +0800 Message-ID: <101c24cfc81ed5819d93c60cf2e96bdd6ce97c47.1630561295.git.ryder.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Ben Greear Without this change, garbage is seen in the hwmon name and sensors output for mt7915 is garbled. It appears that the hwmon logic does not make a copy of the incoming string, but instead just copies a char* and expects it to never go away. Fixes: d6938251bb5b ("mt76: mt7915: add thermal sensor device support") Signed-off-by: Ben Greear Signed-off-by: Ryder Lee --- v6: Use devm_kasprintf to add a generic prefix "mt7915-" on wiphy name. Drop an unrelated change. v5: Use devm_kstrdup on the wiphy name as suggested. v4: Simplify flow. v3: Add 'fixes' tag to aid backports. --- drivers/net/wireless/mediatek/mt76/mt7915/init.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/init.c b/drivers/net/wireless/mediatek/mt76/mt7915/init.c index acc83e9f409b..f43e4077489b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/init.c @@ -160,9 +160,12 @@ static int mt7915_thermal_init(struct mt7915_phy *phy) struct wiphy *wiphy = phy->mt76->hw->wiphy; struct thermal_cooling_device *cdev; struct device *hwmon; + const char *name; - cdev = thermal_cooling_device_register(wiphy_name(wiphy), phy, - &mt7915_thermal_ops); + name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7915-%s", + wiphy_name(wiphy)); + + cdev = thermal_cooling_device_register(name, phy, &mt7915_thermal_ops); if (!IS_ERR(cdev)) { if (sysfs_create_link(&wiphy->dev.kobj, &cdev->device.kobj, "cooling_device") < 0) @@ -174,8 +177,7 @@ static int mt7915_thermal_init(struct mt7915_phy *phy) if (!IS_REACHABLE(CONFIG_HWMON)) return 0; - hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev, - wiphy_name(wiphy), phy, + hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev, name, phy, mt7915_hwmon_groups); if (IS_ERR(hwmon)) return PTR_ERR(hwmon); -- 2.29.2