Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1304175rdb; Sun, 8 Oct 2023 01:06:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFB4Out1DNXmv9ZIQSJlFoTp8dEKEUzM0LxirFreacWexyyST4M1id5NiPEZs4CGNH15c4q X-Received: by 2002:a05:6a00:8c7:b0:68b:e710:ee9c with SMTP id s7-20020a056a0008c700b0068be710ee9cmr14709498pfu.19.1696752418053; Sun, 08 Oct 2023 01:06:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696752418; cv=none; d=google.com; s=arc-20160816; b=sV5lUL38GcoKR0F5p/7xV8aZCo4i4a9073/0U1jCxnUmtX00JR3R4hI9eGJsVRFB7W LgEqo+LldF6oPcafVbJ/1lTfu9EMwZGrQMGI/QZ7ubCzb1hciwbnOHn9DhOPXDVv/AuD O9aEOPU3j45Mi0LZgkdoNeVXL2JJDlFDh40z4/itpSCRPUjI9k7J30w5SLlB1Q6a4Rkr GAFACbKJoVMZ4WQyPj9l3xHbI3jOrrDHxVYGX2Kyr6S5tvH0F8nyRz1yJJM3Llz2uYqt k5hWATny67z1mIQ/Z308tuurQlaZtCnacYl1RLx0vvkylOC3v1pBqVGmX3yUS/KZ+8Wc zEfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=6NNjJMeOlmXb+C0Wu+rZPX2/Cj6tCL3Jb4+7CjKwBrs=; fh=mM7N/Ol4ZMmcte2uo5ht43eN6l+8E4/iA5BSPPzcKlQ=; b=qMD0gRMpGHaqLMMukYsBdJsfzvcNhJ+OJYjwWDgbMgmZtfgdzmoh1kJWzxZfeik9Nj yQgguaLnIY3WGhVzrjBKzduN/+SR3jyFsPqOjqqzSUcXKf3sXweZT3P5nnXMs2QL3qsg 6tUV/kebUjw4zTaMvVRnLGT3BR5k/ODoroPpTI18oDo3IQBf4EGbdmQS1Xe2Qi2u9Dsc Bkl1zHotPgUJXvPLX8J4wpefIfsV59+LMxLIQgyPRZPsBGnrV78GSZACV8mmnjN0L7MG uq6a5SYyfmLrH6h1Fy4o7L6uuEHE4+UfmACBUE5ohl8dbAhPWntmydoXtUtmRtbGb8zR XG5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g7I8NfMY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id m1-20020a656a01000000b00578da0d5b6bsi8137622pgu.724.2023.10.08.01.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 01:06:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g7I8NfMY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id ABFF98067F50; Sun, 8 Oct 2023 01:06:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234215AbjJHIF4 (ORCPT + 99 others); Sun, 8 Oct 2023 04:05:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbjJHIFz (ORCPT ); Sun, 8 Oct 2023 04:05:55 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBC59C5; Sun, 8 Oct 2023 01:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696752353; x=1728288353; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=SNNpZq9DeJkCOqcsWszbC19a6ENGnr7eTy1pzxaaE98=; b=g7I8NfMYDBbLtuFdc43hckw4fRiOablrAPEZ8hyyX2fNfJSIoBSaK7Hi /PzNvkhxePjq1/G48qhthTQt/bfgcdrZYot7JBiLyItENSLZoCvdblyyP rwzafGPg0n+IKj0rNvK2vWxes7vb+1Cty0aJEjuaMlitxctglD9qNEkGS 4OE4SC1pHDyHfnU1g66+Ggr4Gtnv+CEb8blwRajfI4vhVijJoAWPeGHAV 3KZTu5sQHPSEf1408OQLY8tQvapEL1WiExxMBsDHFmdczBhX4LfjOkuxg R2oO8gadBK394prlLv5r+8XWPS17GmiQHckgLcYi0dZiBxQu+2S0P59zZ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10856"; a="383864087" X-IronPort-AV: E=Sophos;i="6.03,207,1694761200"; d="scan'208";a="383864087" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2023 01:05:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10856"; a="876474855" X-IronPort-AV: E=Sophos;i="6.03,207,1694761200"; d="scan'208";a="876474855" Received: from qiuxu-clx.sh.intel.com ([10.239.53.109]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2023 01:05:50 -0700 From: Qiuxu Zhuo To: Borislav Petkov , Tony Luck Cc: Lili Li , James Morse , Mauro Carvalho Chehab , Robert Richter , Qiuxu Zhuo , linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] EDAC/device: Fix potential slab-use-after-free Date: Sun, 8 Oct 2023 16:02:30 +0800 Message-Id: <20231008080231.51917-2-qiuxu.zhuo@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231008080231.51917-1-qiuxu.zhuo@intel.com> References: <20231008080231.51917-1-qiuxu.zhuo@intel.com> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 08 Oct 2023 01:06:05 -0700 (PDT) X-Spam-Level: ** From: Lili Li If the EDAC driver invokes edac_device_alloc_ctl_info() with pvt_sz=0, the EDAC driver itself may manage 'pvt_info' and the EDAC core shouldn't kfree it when unloading the EDAC driver. Otherwise it may lead to a slab-use-after-free bug. Fix the potential bug by adding a flag to indicate whether 'pvt_info' is managed by the EDAC core. The EDAC core will only kfree 'pvt_info' when the flag is set to true. Fixes: 9fb9ce392aae ("EDAC/device: Get rid of the silly one-shot memory allocation in edac_device_alloc_ctl_info()") Suggested-by: Qiuxu Zhuo Signed-off-by: Lili Li --- drivers/edac/edac_device.c | 1 + drivers/edac/edac_device.h | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c index 0689e1510721..b990431df2eb 100644 --- a/drivers/edac/edac_device.c +++ b/drivers/edac/edac_device.c @@ -100,6 +100,7 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance goto free; dev_ctl->pvt_info = pvt; + dev_ctl->pvt_managed_by_edac_core = true; } dev_ctl->dev_idx = device_index; diff --git a/drivers/edac/edac_device.h b/drivers/edac/edac_device.h index 3f44e6b9d387..cc6a364a4b83 100644 --- a/drivers/edac/edac_device.h +++ b/drivers/edac/edac_device.h @@ -197,6 +197,11 @@ struct edac_device_ctl_info { const char *dev_name; /* pci/platform/etc... name */ void *pvt_info; /* pointer to 'private driver' info */ + /* + * Indicate whether the resource pointed by pvt_info is managed by + * the EDAC core. + */ + bool pvt_managed_by_edac_core; unsigned long start_time; /* edac_device load start time (jiffies) */ @@ -355,7 +360,8 @@ extern const char *edac_layer_name[]; static inline void __edac_device_free_ctl_info(struct edac_device_ctl_info *ci) { if (ci) { - kfree(ci->pvt_info); + if (ci->pvt_managed_by_edac_core) + kfree(ci->pvt_info); kfree(ci->attribs); kfree(ci->blocks); kfree(ci->instances); -- 2.17.1