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=-0.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 6751FC433E1 for ; Wed, 3 Jun 2020 18:36:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 196912074B for ; Wed, 3 Jun 2020 18:36:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="UrFdmmKr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 196912074B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 62E7980007; Wed, 3 Jun 2020 14:36:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5DDC18E0006; Wed, 3 Jun 2020 14:36:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CBD280007; Wed, 3 Jun 2020 14:36:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id 3735E8E0006 for ; Wed, 3 Jun 2020 14:36:53 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E4724181AC1E9 for ; Wed, 3 Jun 2020 18:36:52 +0000 (UTC) X-FDA: 76888757064.27.band98_3bfcabef7fe09 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id B1BE8245F01 for ; Wed, 3 Jun 2020 18:36:52 +0000 (UTC) X-HE-Tag: band98_3bfcabef7fe09 X-Filterd-Recvd-Size: 4748 Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Wed, 3 Jun 2020 18:36:52 +0000 (UTC) Received: by mail-qv1-f65.google.com with SMTP id e20so1646217qvu.0 for ; Wed, 03 Jun 2020 11:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=m0rQ25Og4KY67XYe+Rp/bn9zFlsT+AzGVQ1QokPo2LI=; b=UrFdmmKr38oQJnGeMSKPQDnYV5MOF6hN3NmIRhve2nLp8UI3hW+i5z082y6E5pvd05 76amIpm7FGJoaVijfEGwCShv48zdZ0W4lP8GE4ukxay7gLBqddncOQAGAEUltBDEYrkk i0gNcX3r+zW1RpZBEr9iTJPPu0gQeO6knUXi/NOBTCHwm7elDgThK4kaGHky8FvLreTE 10ugU8WYd9sGv7QbLMfM9agMZGbxRJruu/C0g6DB1fIgSYg2uol828JSYBRJZ+OxM2OX eyOnkj/D0FLfu4GB60mpPFXt1ZEvS721uTlge5+kEVvswAC7V1YeMsENm0PWvemibW5q Z31Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=m0rQ25Og4KY67XYe+Rp/bn9zFlsT+AzGVQ1QokPo2LI=; b=teE3yCN4VpgC3l8OXal5GYSRyp6ApGNtID9/uWo2RkOrx8nvA6BnMSUmo3SnD2biS9 wORPTv9E2iZvJDD+CEwtjp3mN2PMnMp3GPNF6U/LJG8651gkz5C2+0+yLZzhhohPO5RO sZPnFcJ2E/QB0cH7UyI0wgosV3ZNDSntyscCknsQMsO69fxXmnt67WEnpyORnb+qRuBJ QYaqM9YTzeitucD5qwjrk7CYbgeLlKH5YyKjEtq3DYPOVo00qYL/VUWGT3FTDTqORjQO V9O9Np/mYmKTZXQcyUJDHqTm730VHnFj3hPSSwBZz9w1TDzutCD/3m8E7Lx0EOE4lI5e MUPw== X-Gm-Message-State: AOAM531YfcMkXp5A84eGhapz1EFW7RXcf2FQunnKLNHCunsfUUc/ec9p v4m/GXVmOoKOSeD/lMpFn+s9Hw== X-Google-Smtp-Source: ABdhPJyszoT0ZrWarMb/dYpGDGoltgyIIt9hGLvyv5t1wF1VrmyYpDnGTIJiTHW/1DcvjIgdM6CevA== X-Received: by 2002:ad4:56e3:: with SMTP id cr3mr1169655qvb.175.1591209411506; Wed, 03 Jun 2020 11:36:51 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id x13sm2178986qkj.36.2020.06.03.11.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2020 11:36:50 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.93) (envelope-from ) id 1jgYFu-000qna-GW; Wed, 03 Jun 2020 15:36:50 -0300 Date: Wed, 3 Jun 2020 15:36:50 -0300 From: Jason Gunthorpe To: James Bottomley Cc: Greg Kroah-Hartman , Matthew Wilcox , Wang Hai , cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, khlebnikov@yandex-team.ru, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: kobject_init_and_add is easy to misuse Message-ID: <20200603183650.GI6578@ziepe.ca> References: <20200602115033.1054-1-wanghai38@huawei.com> <20200602121035.GL19604@bombadil.infradead.org> <1591111514.4253.32.camel@HansenPartnership.com> <20200602173603.GB3579519@kroah.com> <1591127656.16819.7.camel@HansenPartnership.com> <20200602200756.GA3933938@kroah.com> <1591134670.16819.18.camel@HansenPartnership.com> <20200603002205.GE6578@ziepe.ca> <1591207475.4462.41.camel@HansenPartnership.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1591207475.4462.41.camel@HansenPartnership.com> X-Rspamd-Queue-Id: B1BE8245F01 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Jun 03, 2020 at 11:04:35AM -0700, James Bottomley wrote: > On Tue, 2020-06-02 at 21:22 -0300, Jason Gunthorpe wrote: > > On Tue, Jun 02, 2020 at 02:51:10PM -0700, James Bottomley wrote: > > > > > My first thought was "what? I got suckered into creating a patch", > > > thanks ;-) But now I look, all the error paths do unwind back to > > > the initial state, so kfree() on error looks to be completely > > > correct. > > > > It doesn't fully unwind if the kobject is put into a kset, then > > another thread can get the kref during kset_find_obj() and kfree() > > won't wait for the kref to go to 0. It must use put. > > That does seem a bit contrived: the only failure kobject_add_internal() > can get after kobj_kset_join() is from directory creation. If > directory creation fails, no name appears in sysfs and no event for the > name is sent, how did another thread get the name to pass in to > kset_find_obj()? The other thread just guesses in a hostile way? Eg it looks like the iommu stuff just feeds in user data to kobj_kset_join(). Jason