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=-8.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 BCB27C33CB2 for ; Wed, 29 Jan 2020 06:26:21 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 62E3A2067C for ; Wed, 29 Jan 2020 06:26:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62E3A2067C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 486tmC4T7hzDqYk for ; Wed, 29 Jan 2020 17:26:19 +1100 (AEDT) Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 486sF35R2gzDqNf for ; Wed, 29 Jan 2020 16:17:43 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Received: by ozlabs.org (Postfix, from userid 1034) id 486sF12qt1z9sSD; Wed, 29 Jan 2020 16:17:40 +1100 (AEDT) X-powerpc-patch-notification: thanks X-powerpc-patch-commit: aff8c8242bc638ba57247ae1ec5f272ac3ed3b92 In-Reply-To: <1579558202-26052-1-git-send-email-tyreld@linux.ibm.com> To: Tyrel Datwyler From: Michael Ellerman Subject: Re: [PATCH] powerpc/pseries/vio: Fix iommu_table use-after-free refcount warning Message-Id: <486sF12qt1z9sSD@ozlabs.org> Date: Wed, 29 Jan 2020 16:17:40 +1100 (AEDT) X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tyrel Datwyler , aik@ozlabs.ru, Tyrel Datwyler , drt@linux.ibm.com, linuxppc-dev@lists.ozlabs.org, david@gibson.dropbear.id.au Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Mon, 2020-01-20 at 22:10:02 UTC, Tyrel Datwyler wrote: > From: Tyrel Datwyler > > Commit e5afdf9dd515 ("powerpc/vfio_spapr_tce: Add reference counting to > iommu_table") missed an iommu_table allocation in the pseries vio code. > The iommu_table is allocated with kzalloc and as a result the associated > kref gets a value of zero. This has the side effect that during a DLPAR > remove of the associated virtual IOA the iommu_tce_table_put() triggers > a use-after-free underflow warning. > > Call Trace: > [c0000002879e39f0] [c00000000071ecb4] refcount_warn_saturate+0x184/0x190 > (unreliable) > [c0000002879e3a50] [c0000000000500ac] iommu_tce_table_put+0x9c/0xb0 > [c0000002879e3a70] [c0000000000f54e4] vio_dev_release+0x34/0x70 > [c0000002879e3aa0] [c00000000087cfa4] device_release+0x54/0xf0 > [c0000002879e3b10] [c000000000d64c84] kobject_cleanup+0xa4/0x240 > [c0000002879e3b90] [c00000000087d358] put_device+0x28/0x40 > [c0000002879e3bb0] [c0000000007a328c] dlpar_remove_slot+0x15c/0x250 > [c0000002879e3c50] [c0000000007a348c] remove_slot_store+0xac/0xf0 > [c0000002879e3cd0] [c000000000d64220] kobj_attr_store+0x30/0x60 > [c0000002879e3cf0] [c0000000004ff13c] sysfs_kf_write+0x6c/0xa0 > [c0000002879e3d10] [c0000000004fde4c] kernfs_fop_write+0x18c/0x260 > [c0000002879e3d60] [c000000000410f3c] __vfs_write+0x3c/0x70 > [c0000002879e3d80] [c000000000415408] vfs_write+0xc8/0x250 > [c0000002879e3dd0] [c0000000004157dc] ksys_write+0x7c/0x120 > [c0000002879e3e20] [c00000000000b278] system_call+0x5c/0x68 > > Further, since the refcount was always zero the iommu_tce_table_put() > fails to call the iommu_table release function resulting in a leak. > > Fix this issue be initilizing the iommu_table kref immediately after > allocation. > > Fixes: e5afdf9dd515 ("powerpc/vfio_spapr_tce: Add reference counting to iommu_table") > Signed-off-by: Tyrel Datwyler Applied to powerpc next, thanks. https://git.kernel.org/powerpc/c/aff8c8242bc638ba57247ae1ec5f272ac3ed3b92 cheers