Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1567504pxa; Thu, 6 Aug 2020 10:26:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxG6dT1Gva6+CfKenYuChh9/D4dYZETklSqIql3MVaq0RWthJsDFe4f6LJrtsmR19rFLlx1 X-Received: by 2002:a17:906:7fc9:: with SMTP id r9mr5219797ejs.407.1596734793792; Thu, 06 Aug 2020 10:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596734793; cv=none; d=google.com; s=arc-20160816; b=hOeCh6ZNviSC6hy5IPfEYjFzgmRmkTTi8nAIu4Wejn4NXkWiCM35QTUq3b7saHhC9r yb3tgvnxBZyoIjzK7l8wDEfhJifUD9Izip8wUPzIbF6Zf8ZBI5GCfmMBR7SXfwFs7ntU pDAvWY+WFDh/QSJX+ujt0juTtlRJI9y9WJvJ5HJl+NPeRwOVyAVwjgKjwAZohi4azh94 LUFESmCd798yEDRDdrhBXY8zAzlly4Jfgys+9mOTCaXg8ZVMMMTZaSiLP2KBjGFVf7q9 3Y0J7AF31tzs0W83B/is4xSkUaaYGuj7BFLZeEAITc5tzDPR4wFJ2yXAalqAg64VivLO 7P7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=V1nnod0YcV7H2TUfC8Gd96YGz+LSO9JcTYXXX1K5F8M=; b=XEvL/4QVjW9uMuXBt8NONTDPnqKX2rqlo0N98Y8A0KyvU0MfGZFO6NnTY/IB2Na07x Wu5UsFKFi82HCBWb9At0eP0JI6pM8QWHdlXUtnBzKq0+j7cR6NHM0d8ULP2ATGuE/XDp HAyZ61e7D9xDbbX+Oaa6Z7gECnj5FN2nD0Bxmd90+zOVjecWtd7hiCInLfhjyDgcgY+/ t1zXo54T1LfKjts58l53j2zp/0vr7otbBvXArfg/WoR+Q1fhPSeD2IZzK9cYbTLca4JC 4O/KzKNqY7xmkISA3fHhDgKipfS0GvIZRpEskcpCt6SeKaqZ/p4Uz+m0aiA5A8LWPQ+H mwRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@etsukata-com.20150623.gappssmtp.com header.s=20150623 header.b=YKSScdMP; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cb11si3525846edb.344.2020.08.06.10.26.11; Thu, 06 Aug 2020 10:26:33 -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=@etsukata-com.20150623.gappssmtp.com header.s=20150623 header.b=YKSScdMP; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730009AbgHFRZU (ORCPT + 99 others); Thu, 6 Aug 2020 13:25:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728735AbgHFRDC (ORCPT ); Thu, 6 Aug 2020 13:03:02 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF19CC034615 for ; Thu, 6 Aug 2020 06:19:13 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id s15so15145180pgc.8 for ; Thu, 06 Aug 2020 06:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsukata-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=V1nnod0YcV7H2TUfC8Gd96YGz+LSO9JcTYXXX1K5F8M=; b=YKSScdMPWzgWF7wSGiSqP95WaTCqorzQjkBnqwiKacTI0pfodkP5JNyOASut44yJ3s l5WouG2nks7VRPeOnmuKSKOFIZh8Ic0u8UuUxx45NqhalbT1S4f/9zdk9NtVZOzxRZIQ 5aiTXswxQAVqbhKii8Csr+ntnUijgnCyA7hcfIOHIXy36EYCI/cakomgU/tpxjmQzq1D 2pwabp9JoYYNme1qeEGLFdWuN+eKF79/Trev97gkXlSZWXu0VOo/HKohGN680R/9FDPI Ere7hd6MEpRJtverCfv4jb0jqpZkVGowXiQuFo/kT+QYEJlC6cIka8DF1SLC/s5p6s+X Ichw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=V1nnod0YcV7H2TUfC8Gd96YGz+LSO9JcTYXXX1K5F8M=; b=iF7i09/mKC/fAy3lFE5KN6mkPl4wgMnktQdGl8cUqf1QAnC/CETovUk3ZgGjh1dMxh TLFbxlawUXLOBtOdDkRQ5PAi5XouEEDfa/sxvkH+o0ct5OO3h11u3R2xM86de5tN1z02 VfdPBQa1KdRLMf/x78vJcWTBoUX/UrSO89auS0IF6wdkXlOEwL19TyNct2Fv+OguGLNj oyIpTuVL22dc+FE80qrk4O1A5qaAE/+BF6a6fycjbTcT/dd28WUYK5PuOJisZt+l3447 dfYlboRN1yMblxJo/qAnAUOQte45P/zYrfRmaprRyaKfCQONSms+53NtfwL2p1KGfga8 W/bw== X-Gm-Message-State: AOAM531WhGXT+6985KCiUTAfo6msZee/iwzDx5x/MSgW+emEr1JOFT/e o3iG0+e/3Bv7Nr9oK4EXwLklI8WVcRI= X-Received: by 2002:aa7:982e:: with SMTP id q14mr8418876pfl.299.1596719950852; Thu, 06 Aug 2020 06:19:10 -0700 (PDT) Received: from localhost.localdomain (p14232-ipngn10801marunouchi.tokyo.ocn.ne.jp. [122.24.13.232]) by smtp.gmail.com with ESMTPSA id y72sm8790366pfg.58.2020.08.06.06.19.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 06:19:09 -0700 (PDT) From: Eiichi Tsukata To: darrick.wong@oracle.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Eiichi Tsukata Subject: [PATCH] xfs: Fix UBSAN null-ptr-deref in xfs_sysfs_init Date: Thu, 6 Aug 2020 22:18:47 +0900 Message-Id: <20200806131847.2248244-1-devel@etsukata.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If xfs_sysfs_init is called with parent_kobj == NULL, UBSAN shows the following warning: UBSAN: null-ptr-deref in ./fs/xfs/xfs_sysfs.h:37:23 member access within null pointer of type 'struct xfs_kobj' Call Trace: dump_stack+0x10e/0x195 ubsan_type_mismatch_common+0x241/0x280 __ubsan_handle_type_mismatch_v1+0x32/0x40 init_xfs_fs+0x12b/0x28f do_one_initcall+0xdd/0x1d0 do_initcall_level+0x151/0x1b6 do_initcalls+0x50/0x8f do_basic_setup+0x29/0x2b kernel_init_freeable+0x19f/0x20b kernel_init+0x11/0x1e0 ret_from_fork+0x22/0x30 Fix it by checking parent_kobj before the code accesses its member. Signed-off-by: Eiichi Tsukata --- fs/xfs/xfs_sysfs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_sysfs.h b/fs/xfs/xfs_sysfs.h index e9f810fc6731..aad67dc4ab5b 100644 --- a/fs/xfs/xfs_sysfs.h +++ b/fs/xfs/xfs_sysfs.h @@ -32,9 +32,9 @@ xfs_sysfs_init( struct xfs_kobj *parent_kobj, const char *name) { + struct kobject *parent = parent_kobj ? &parent_kobj->kobject : NULL; init_completion(&kobj->complete); - return kobject_init_and_add(&kobj->kobject, ktype, - &parent_kobj->kobject, "%s", name); + return kobject_init_and_add(&kobj->kobject, ktype, parent, "%s", name); } static inline void -- 2.26.2