Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp316524pxj; Thu, 20 May 2021 09:59:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfWkwT0yUBeiCXvdA3Q/17kNvk4GQchcVrC8ONkdhTWAoP6+ngbesfDnLDH6VJhyghLoeC X-Received: by 2002:a6b:4f17:: with SMTP id d23mr6263803iob.91.1621529956365; Thu, 20 May 2021 09:59:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621529956; cv=none; d=google.com; s=arc-20160816; b=OD9fhjBDiCUvd2GQ7vTTnc/RpfphjA1BS5F/ClaJM7BU7R+XEYt34T5Hf7LNUp84+L kOJgZJX9F9kEZp9NZq6JisD26yLYuWTogtDcPVG1m4P/f5M9mM8sxr9kl9Iem621YGjB RyU2j+Gd47ExNCqEbEsaFy0VA5lOAoZjyIcWZupQQzzbOse9cTUTFXuZGbwy5gFv3iO/ IBCzEF8ICh34fR5Vw4ZxDJWZKbi8rDi5bxNFyjUiQNtAf8fouH6obrRo3SXhVcGLEp3e oYa0sg9bU9gCySIKq4hhfTZpmf13NpSi3S1maRvalkzFJtHtCBp3xz7GMxwDybVIjLly Yt1Q== 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=ez9xK0tVu2EaLs9PFLvWZR5g+lxZ+Ja6ebgk4r9Regw=; b=delhgXNvsIXgKMClEH6cEnvYEFVHAKfL4TFRysE9M9YU2tF4NSBIFawZccSVZFCGoR QV3T5AKcqUU7T2/vgslpvmR2oc3MsMeXfJi2YOhckF2XJO2nSiXLcFbDHw3O3lDuhTM7 DE65UOoDwOOPAObHulXQi0WfQZ5KZHlwAme7t7CRhILGKQofPkFLLJcx4G+yCVuCYQSU ZMOj5NLxhfuGidRNlnrnC8e5R17PbhEq+LbMZAvn3oTHasy+MRqCyB42CRFl75suWj6X gdtLKEnL/clnIieHtD1v8/bjdYTYukYBp3UE8AzzXsdL2i/n8riXYjNy13qUkJJFnSUI vmpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aZd7riVp; 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 z17si2556159jat.5.2021.05.20.09.59.03; Thu, 20 May 2021 09:59:16 -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=aZd7riVp; 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 S234917AbhETKB0 (ORCPT + 99 others); Thu, 20 May 2021 06:01:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:58652 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232190AbhETJ5D (ORCPT ); Thu, 20 May 2021 05:57:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1FD4861628; Thu, 20 May 2021 09:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503471; bh=IoqobeW3DHyKT2pgDL6szVyKYu+QV47NWdt3pHMoXEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aZd7riVpfNUSnOal+g33msXFimJsWflCt3zGt+Lz+c228JHBXZiE9RVjFpNVkLp83 EnyjXKMWZsZMjKwjvHHLcFLnUDa6NmFjwyFdKO6CpTtDmwrILapd8EV0AAWEtj0+PY nSh7KA6S+GbQcBmR+dWU7gH07wbsC9jaxw/9suYI= 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 4.19 236/425] vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer Date: Thu, 20 May 2021 11:20:05 +0200 Message-Id: <20210520092139.186417390@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 1692a0cc3036..c99fcc6c2eba 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -108,6 +108,7 @@ 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), @@ -135,7 +136,6 @@ struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, } type->group = group; - type->parent = parent; return type; attrs_failed: -- 2.30.2