Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1423007rwe; Sat, 27 Aug 2022 07:51:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR4STiHSZwgI/kTINWuAsvrQQO3S7tuffQHSsHy1fkYv0OcOAuxyfozEt7Ekvhu7wl8snk46 X-Received: by 2002:a17:90b:3655:b0:1fb:8ef:5da6 with SMTP id nh21-20020a17090b365500b001fb08ef5da6mr9555170pjb.81.1661611863921; Sat, 27 Aug 2022 07:51:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661611863; cv=none; d=google.com; s=arc-20160816; b=JmGjE9HaDMS6Rb7F1FybCjY9XgG0CFjkrz6mq91QIviz2mzt9nwLaxu26uSYZF7l7d xejbfjCLbgPkvFWEU1PCsydplzhqDLTg5ZEMlxI/EKfxV+gX1jwhogOi7bNRo9u01PjZ xh86WEonM52eALryOOvBoGCxfLZLLFw1xyIgdh6DG769B/FzgS2Ixph1ZkHLZp7aE/Ce KXhSiPmfCDQ/UPB+bvYxWzf1dDpsOHnCe9cLx89raokpqvEutxxxBgzKkcaNIVgbud09 hTd3X+o0B/YjNGSNpXExOwe9vOhfvcRl4B5tduGIZflkilXMnX/IhRR5HTaGeysOKRuL JhWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=sqJLqJmdQlQoWSKIiPgI6ueaPeloULLjAt+voS3na84=; b=Q6jzSyfjGJq9MtDdbGSGhfjoKRf1FEdvqtTUFUlaUnPIDMOf4QyusxLKkZXFuCrupE cfacH+8fzLtDGr+iriAW9xdklAAL+B22KqmvnwyTj6fTZUBMXjDXxH22hIMT6R0gWzei Z1C3Fc8zfQyO0xJdmj6zb9L89Svo7KEqaE6Cfv0iJNe/HijCS6CT8f3nhbTczeIhwjry QpfuHsQ6S3LuZyP7VXnRSAJRsPZUsb6dtCkNysYcspmbXohrCDuMc19Y1X7vZYPZCWAP EkMYS4fVFtlj18n3gfLVEi/zR+PKUYbjcP7eKoBZ2XD0pn/Y0Rt0lW6cwshNgBJ0ISEO Lf2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s5-20020a656445000000b0042b8d806ec7si3146053pgv.694.2022.08.27.07.50.52; Sat, 27 Aug 2022 07:51:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233358AbiH0OJt (ORCPT + 99 others); Sat, 27 Aug 2022 10:09:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233346AbiH0OJs (ORCPT ); Sat, 27 Aug 2022 10:09:48 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F7764D173; Sat, 27 Aug 2022 07:09:43 -0700 (PDT) Received: from hednb3.intra.ispras.ru (unknown [109.252.119.247]) by mail.ispras.ru (Postfix) with ESMTPSA id B6E7B40737C1; Sat, 27 Aug 2022 14:09:39 +0000 (UTC) From: Alexey Khoroshilov To: Alexander Viro Cc: Rustam Subkhankulov , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov , ldv-project@linuxtesting.org Subject: [PATCH] fs/inode.c: change the order of initialization in inode_init_always() Date: Sat, 27 Aug 2022 17:09:26 +0300 Message-Id: <1661609366-26144-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rustam Subkhankulov If function 'security_inode_alloc()' returns a nonzero value at [fs/inode.c: 195] due to an error (e.g. fail to allocate memory), then some of the fields, including 'i_private', will not be initialized. After that, if the fs-specfic free_inode function is called in 'i_callback', the nonzero value of 'i_private' field can be interpreted as initialized. As a result, this can cause dereferencing of random value pointer (e.g. nilfs2). In earlier versions, a similar situation could occur with the 'u' union in 'inode' structure. Found by Linux Verification Center (linuxtesting.org) with syzkaller. Signed-off-by: Rustam Subkhankulov Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") --- fs/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index bd4da9c5207e..08d093737e8c 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -192,8 +192,6 @@ int inode_init_always(struct super_block *sb, struct inode *inode) inode->i_wb_frn_history = 0; #endif - if (security_inode_alloc(inode)) - goto out; spin_lock_init(&inode->i_lock); lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key); @@ -230,9 +228,10 @@ int inode_init_always(struct super_block *sb, struct inode *inode) inode->i_flctx = NULL; this_cpu_inc(nr_inodes); + if (security_inode_alloc(inode)) + return -ENOMEM; + return 0; -out: - return -ENOMEM; } EXPORT_SYMBOL(inode_init_always); -- 2.34.1