Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4611439pxj; Wed, 12 May 2021 09:13:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycU2cJ2Eah12oCIWp8TgMi1U+FIJwfWNwnmfdP1XhFVZWzJhPadkEFscNlkT5sUzAJOncU X-Received: by 2002:a05:6402:19a:: with SMTP id r26mr43752134edv.44.1620835983608; Wed, 12 May 2021 09:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835983; cv=none; d=google.com; s=arc-20160816; b=bTlpyhzlhgs/zLjYs5WZ++dUUs8p396rrmUj2n1iTPHbIRPDR/8dKxZ3ALc0oTSUSP 4DTgf9OJ2O8B/PyHm0Ba4TA1zsST4Dq3r2b5lELe27NmcSf6I390Ljtf8TTV+GQ5iHnu gyPhwuVUx3ZQr/FQxxhr62dDQ4QoQ8VWbK5LEDu9ohf1lD/+ov550/BuFrtU/Qybe9Xe TmFFyJs+u698Nuk4ILNPaQVTSWwZTWGzgSVD7zi3p6vpSs1+WjDl+jEXVv0solnMRnmB SjPg5Rj529VJYQlSFzbATyivZF09tIbUXZmjhjNELF9tGivQFUT1tB+28JMsQ3QOc6Rr leTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XkCD2lrTzDQV9oasQzmF/TPBLXnrtPso0qMocv0nF3M=; b=UcD5LoV+4BTHNw1TVSZX8VG5whsxz2kBFo078y4yuLta7kOr6FiD6LlN9Wz2k2AueV TmZO+LZZVVzOhB6K0WJQBdPoymcQLeryeBu8La3bj5YmgSPYxwHH7eq6PusJnHFHiu/D Nru6TUrVU6lk69CSPSAVbEFnTpQcMsbdhWDWohAlHLUs/BOrW6wU9u9SLJ9K0OF1QJ7+ /UIg6MrHgs6kUrwGCVTwoXQg36b8GeYtAEZaiFui+9NF7cGBhzdHo3WMmhijIvJX1yW/ Tjj51FG2NnZbBCuUPfK7pebaUZ4Jdp6lBjBfoTEFma0DysVdjq9Ir1WgV5u1qxjqK74e WITw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Dg0APFGE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb8si120959edb.49.2021.05.12.09.12.37; Wed, 12 May 2021 09:13:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Dg0APFGE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239636AbhELQKZ (ORCPT + 99 others); Wed, 12 May 2021 12:10:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:46626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235118AbhELP3v (ORCPT ); Wed, 12 May 2021 11:29:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9EEDB61946; Wed, 12 May 2021 15:15:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832535; bh=TH9HxxzcUuVWYmDueDD75n9GZ1q7nkDozQBjGxUNubM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dg0APFGEs+KVEZOvN4NHDMfof/0EfLc7g9cz7God2+P8+H86s9/ampobNyidY8WMw qTCtDTfapn3UbL4Wa7oRXepPSpoalXxM9E1gsbugDI5+WXxgT7NbWgjrwhkB4MdICF D1Fcw7i/+rGhzCk2IAvGrzPWv6zPFOXLLiITMg9A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Kevin Tian , Max Gurtovoy , Cornelia Huck , Jason Gunthorpe , Alex Williamson , Sasha Levin Subject: [PATCH 5.10 319/530] vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer Date: Wed, 12 May 2021 16:47:09 +0200 Message-Id: <20210512144830.295205854@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gunthorpe [ Upstream commit b5a1f8921d5040bb788492bf33a66758021e4be5 ] There is a small race where the parent is NULL even though the kobj has already been made visible in sysfs. For instance the attribute_group is made visible in sysfs_create_files() and the mdev_type_attr_show() does: ret = attr->show(kobj, type->parent->dev, buf); Which will crash on NULL parent. Move the parent setup to before the type pointer leaves the stack frame. Fixes: 7b96953bc640 ("vfio: Mediated device Core driver") Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Max Gurtovoy Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe Message-Id: <2-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- drivers/vfio/mdev/mdev_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 917fd84c1c6f..367ff5412a38 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -105,6 +105,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, return ERR_PTR(-ENOMEM); type->kobj.kset = parent->mdev_types_kset; + type->parent = parent; ret = kobject_init_and_add(&type->kobj, &mdev_type_ktype, NULL, "%s-%s", dev_driver_string(parent->dev), @@ -132,7 +133,6 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, } type->group = group; - type->parent = parent; return type; attrs_failed: -- 2.30.2