From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.4 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1908C4CECE for ; Mon, 14 Oct 2019 17:30:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6E95720663 for ; Mon, 14 Oct 2019 17:30:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alien8.de header.i=@alien8.de header.b="CpG5dgqJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388526AbfJNRaP (ORCPT ); Mon, 14 Oct 2019 13:30:15 -0400 Received: from mail.skyhub.de ([5.9.137.197]:53880 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388524AbfJNRaP (ORCPT ); Mon, 14 Oct 2019 13:30:15 -0400 Received: from zn.tnic (p200300EC2F065800329C23FFFEA6A903.dip0.t-ipconnect.de [IPv6:2003:ec:2f06:5800:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id CCF651EC0C81; Mon, 14 Oct 2019 19:30:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1571074213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=YXsfaSEH0CXXYfsg24af+D+9Nkrz5SI2FklFgqBg6nI=; b=CpG5dgqJ7UNwi+a+TGHRqbHAlaN/ZBESm7Fudu+wwuXk5u/VZ/9mAQQTsnf07+Rx56ITcN oycd8aOVa3jDo6T0WMZVnO7g9C61UiRoH6HBwKeVFuZxGXfVqVoPGA9aremi7gvHH9zE7w HQPYuGazFYZV2JyGuL4e/89EXg9Gr/s= Date: Mon, 14 Oct 2019 19:30:06 +0200 From: Borislav Petkov To: James Morse Cc: linux-edac@vger.kernel.org, Mauro Carvalho Chehab , Tony Luck , Robert Richter , John Garry Subject: Re: [PATCH 0/2] EDAC, ghes: Fix use after free and add reference Message-ID: <20191014173006.GG4715@zn.tnic> References: <20191014171919.85044-1-james.morse@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191014171919.85044-1-james.morse@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-edac-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org On Mon, Oct 14, 2019 at 06:19:17PM +0100, James Morse wrote: > ghes_edac can only be registered once, later attempts will silently > do nothing as the driver is already setup. The unregister path also > only expects to be called once, but doesn't check. > > This leads to KASAN splats if multiple GHES entries are unregistered, > as the free()d memory is dereferenced, and if we're lucky, free()d > a second time. > > Link: lore.kernel.org/r/304df85b-8b56-b77e-1a11-aa23769f2e7c@huawei.com > > Patch 1 is the minimum needed to prevent the dereference and double > free, but this does expose the lack of symmetry. If we unregister > one GHES entry, subsequent notifications will be lost. > Unregistering is unsafe if another CPU is using the free()d memory in > ghes_edac_report_mem_error(). > > To fix this, Patch 2 uses ghes_init as a reference count. > > We can now unbind all the GHES entries, causing ghes_edac to be > unregistered, and start rebinding them again. > > > Thanks, > > James Morse (2): > EDAC, ghes: Fix Use after free in ghes_edac remove path > EDAC, ghes: Reference count GHES users of ghes_edac Thanks for debugging and fixing this but why two patches? One is perfectly fine IMO. Or? Btw, I admit that the ghes_init thing is ugly as hell. ;-\ I wonder if it could be ripped out completely and we use only ghes_pvt for controlling the single driver instance loading and unloading... -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette