Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp448336pxj; Thu, 20 May 2021 13:10:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwszIIcgGNAOKOy/chXHpTzH9Gp1KBSdTzDmOzKgRKRvQmUUAkdZOPRUo2Jowb5+3fqVltI X-Received: by 2002:a92:c8cb:: with SMTP id c11mr7008233ilq.239.1621541445989; Thu, 20 May 2021 13:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621541445; cv=none; d=google.com; s=arc-20160816; b=qoEDg1WclNpDhNqx9QdfNOUe9aZ7i+mRP9R8qzNkHZYZssMyXThJY0j+tksfpwv52V U7Zn6n/VAsqSIm1RLw0TfcIxCNzTLtUbA8OODnpUMPzfyU892jCSqEeDAsCf+cewJ2YP no0xgVQezGT7/HaAfqXqWFBBX8Oz+3+BbT03apm6d904g4epB2ZF3Jx9hy/s8rzHPdmD uOb9p2SeDwc5ALBgcFzdQA0VaMyOMOjyClVrNvzJ7eXoUMa6TXQtuPGfSLhpZMD3hIW1 R8nrA8dWhm4nLAsL5bN4cmbZZbJTCG8Gesshkpv/kKUHbVf/e1XJA+890tzH/mnZKPB+ HWTQ== 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=Z6Ge//K97pZKf9mTS3noKwaRXGaYwMyG8qVgI/tl0Gc=; b=QucxpxCKn9c/FQ8OFab1Ud/d0wDnwKMGIeJzTnyDCDfpU5OVypKATRlAIga+NFmQba 0F3oxiPSkh9aZq0uwI2Ollk1eglAghnFZJ9roJXU6hgTT7iEFl3z1Su4Y2iLpeMKNOaM ddIla+RkUwhc2xwPVSXRBMGnNhWxo2YB1S88i4gTwei30RsoiZmOgC2A7E8pCHtuEV2R ab0GQdupT6jHqDZ9kqvDN5YAk6SlkIXVSR1nvcFqAtTD+tcYjDB7wgHtMLbxDdJE7R8e JtRGhFTlmAAijzDDkI2lxEydjs2NCJsMOHVdFpZn41j6+bmQT6bhFJyzQcYhCudaU6UR JYaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TJCsNr73; 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 m14si3407451ili.85.2021.05.20.13.10.33; Thu, 20 May 2021 13:10:45 -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=TJCsNr73; 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 S238102AbhETKqg (ORCPT + 99 others); Thu, 20 May 2021 06:46:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:33412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237225AbhETKac (ORCPT ); Thu, 20 May 2021 06:30:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A59ED619A7; Thu, 20 May 2021 09:51:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504310; bh=DlQHfCnXIhrxdegb1dh/H5yqveOeP02fhLYol42uChs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TJCsNr73toFHIfRvu6zGk2ZDqjQIp9eP6QG/BU6ChG6/oxd4rlbwWa5lXOaZKws2V SyiNY5Ngx9tGd55sejFkYr9YA9i/iunbibczEiRr40Ru5+08Xc5zwfAzYhu+fmadcT fHFZiDxJCsmalTrgK/GU/UlH2F5/vtPy+DRs0neM= 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.14 187/323] vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer Date: Thu, 20 May 2021 11:21:19 +0200 Message-Id: <20210520092126.523776885@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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 7e474e41c85e..2dbdefd7b683 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