Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1206318ybf; Thu, 27 Feb 2020 06:48:31 -0800 (PST) X-Google-Smtp-Source: APXvYqw3iIuUr2X1KVFb6dyMIiKKtyCm7K7cWr6vjvtZnPjpDi+DfKEV/HhN5NcYFXLkBnldDpsV X-Received: by 2002:aca:a9d4:: with SMTP id s203mr3686374oie.106.1582814911077; Thu, 27 Feb 2020 06:48:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582814911; cv=none; d=google.com; s=arc-20160816; b=L1z0kUWXnYfyblDtCyZPnEsiBc9h7pd9Nh/iBiHY7boy+m4x9QXeKahYH4DJR7+SXe /BkJmuQUH6GNABf/wf4s19OWOOX3hoVRPciq665fMdFEgyd597iFDjEdOwWubwTu4rZj 9tFw7pyU4CRb2eIaiErFpiQiRnpFHmaRg8bQX9vT3Vv7mB/lprilxf1I4aiRojCyejX+ wuiYS8MmcE8sqysaDCE/IyR3dzZIXfgNlOc8jCaRoDc6Vhti+QD439TarTk9jShJWSeF 1muGzUgMhUyOBO1KCxo8mmvzXUUmVgeyoxT6MiWaF6afZW8LGoDfo1jPYtxW8Mh+fwe8 Av/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KeRzWF2KtdJayLXredV3MJp1lYXHt6Tk+nNdZx9PLFs=; b=HiELbdEd1fOY1qxR8iYnyNHkKclKS6jnwPV4OGEH3rhWC0RXdJ1UvFAsLIh4g8JOV1 c4xeyb9m3M6vzgdbQxvypMDIqjwh3SGB4sE+Yq0UQr45cj6Upd/3aY1wGLvcaq2XayBv K/fAuW8KW4e1IN/NHFHF8zWeq1y75JoyyyQEhVUHlb7SrUl2ZR2BCwlD+yna71anjkLb l/4QfRec7XMU4OOXCz/4jNi8T4Eype7OFt+hU4gIHLqvU8jXnJj/Sq3zsXdST4N019mc C3SMCGVkL9ea6uusHesj9I/8D6FJzilt5biUs5KdW6fKb5uTymZbgjSd/kCpKEYsVsjw aFmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KfuPhHmo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g17si1868976otg.129.2020.02.27.06.48.18; Thu, 27 Feb 2020 06:48:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KfuPhHmo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729221AbgB0Orh (ORCPT + 99 others); Thu, 27 Feb 2020 09:47:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:39448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729591AbgB0NoD (ORCPT ); Thu, 27 Feb 2020 08:44:03 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3E50320726; Thu, 27 Feb 2020 13:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582811042; bh=QA3jeg9gW/R8f7Sgn3etd/gjp/5Lbr+aIijXiYDZ0Yc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KfuPhHmoPtgr3+cEspurKPrQ/Vo63cqKgxWMoQ8ZmytJN5kC1TMq1spbxqvp6BphL Wxo3CrKU7te8XRths7jL4LVqLJf+rKzmEc1J+kjPVk+GULMAc2bYqCy7wbpEYSOv6T f6hAu9BrSy4Gp5BkGQvEIHadk0PUHXT0TXOx9zOU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Borislav Petkov Subject: [PATCH 4.4 093/113] x86/mce/amd: Fix kobject lifetime Date: Thu, 27 Feb 2020 14:36:49 +0100 Message-Id: <20200227132226.622931292@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132211.791484803@linuxfoundation.org> References: <20200227132211.791484803@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner commit 51dede9c05df2b78acd6dcf6a17d21f0877d2d7b upstream. Accessing the MCA thresholding controls in sysfs concurrently with CPU hotplug can lead to a couple of KASAN-reported issues: BUG: KASAN: use-after-free in sysfs_file_ops+0x155/0x180 Read of size 8 at addr ffff888367578940 by task grep/4019 and BUG: KASAN: use-after-free in show_error_count+0x15c/0x180 Read of size 2 at addr ffff888368a05514 by task grep/4454 for example. Both result from the fact that the threshold block creation/teardown code frees the descriptor memory itself instead of defining proper ->release function and leaving it to the driver core to take care of that, after all sysfs accesses have completed. Do that and get rid of the custom freeing code, fixing the above UAFs in the process. [ bp: write commit message. ] Fixes: 95268664390b ("[PATCH] x86_64: mce_amd support for family 0x10 processors") Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Cc: Link: https://lkml.kernel.org/r/20200214082801.13836-1-bp@alien8.de Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/mcheck/mce_amd.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) --- a/arch/x86/kernel/cpu/mcheck/mce_amd.c +++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c @@ -560,9 +560,12 @@ static const struct sysfs_ops threshold_ .store = store, }; +static void threshold_block_release(struct kobject *kobj); + static struct kobj_type threshold_ktype = { .sysfs_ops = &threshold_ops, .default_attrs = default_attrs, + .release = threshold_block_release, }; static int allocate_threshold_blocks(unsigned int cpu, unsigned int bank, @@ -765,8 +768,12 @@ static int threshold_create_device(unsig return err; } -static void deallocate_threshold_block(unsigned int cpu, - unsigned int bank) +static void threshold_block_release(struct kobject *kobj) +{ + kfree(to_block(kobj)); +} + +static void deallocate_threshold_block(unsigned int cpu, unsigned int bank) { struct threshold_block *pos = NULL; struct threshold_block *tmp = NULL; @@ -776,13 +783,11 @@ static void deallocate_threshold_block(u return; list_for_each_entry_safe(pos, tmp, &head->blocks->miscj, miscj) { - kobject_put(&pos->kobj); list_del(&pos->miscj); - kfree(pos); + kobject_put(&pos->kobj); } - kfree(per_cpu(threshold_banks, cpu)[bank]->blocks); - per_cpu(threshold_banks, cpu)[bank]->blocks = NULL; + kobject_put(&head->blocks->kobj); } static void __threshold_remove_blocks(struct threshold_bank *b)