From: Dan Carpenter <error27@gmail.com>
To: zhangpeng362@huawei.com
Cc: ntfs3@lists.linux.dev
Subject: [bug report] fs/ntfs3: Fix null-ptr-deref on inode->i_op in ntfs_lookup()
Date: Thu, 5 Jan 2023 10:12:41 +0300 [thread overview]
Message-ID: <Y7Z4aXWLuR/Uel2u@kili> (raw)
Hello ZhangPeng,
The patch fb6b59b5a2d6: "fs/ntfs3: Fix null-ptr-deref on inode->i_op
in ntfs_lookup()" from Nov 25, 2022, leads to the following Smatch
static checker warning:
fs/ntfs3/namei.c:96 ntfs_lookup()
error: potential NULL/IS_ERR bug 'inode'
fs/ntfs3/namei.c
67 static struct dentry *ntfs_lookup(struct inode *dir, struct dentry *dentry,
68 u32 flags)
69 {
70 struct ntfs_inode *ni = ntfs_i(dir);
71 struct cpu_str *uni = __getname();
72 struct inode *inode;
73 int err;
74
75 if (!uni)
76 inode = ERR_PTR(-ENOMEM);
77 else {
78 err = ntfs_nls_to_utf16(ni->mi.sbi, dentry->d_name.name,
79 dentry->d_name.len, uni, NTFS_NAME_LEN,
80 UTF16_HOST_ENDIAN);
81 if (err < 0)
82 inode = ERR_PTR(err);
83 else {
84 ni_lock(ni);
85 inode = dir_search_u(dir, uni, NULL);
The issue for Smatch is that dir_search_u() returns NULL if the file
is not found, or an error if there is an error, or a valid pointer.
86 ni_unlock(ni);
87 }
88 __putname(uni);
89 }
90
91 /*
92 * Check for a null pointer
93 * If the MFT record of ntfs inode is not a base record, inode->i_op can be NULL.
94 * This causes null pointer dereference in d_splice_alias().
95 */
--> 96 if (!IS_ERR(inode) && inode->i_op == NULL) {
^^^^^^^
Potential NULL dereference. Seems easy to hit too.
97 iput(inode);
98 inode = ERR_PTR(-EINVAL);
99 }
100
101 return d_splice_alias(inode, dentry);
102 }
regards,
dan carpenter
reply other threads:[~2023-01-05 7:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y7Z4aXWLuR/Uel2u@kili \
--to=error27@gmail.com \
--cc=ntfs3@lists.linux.dev \
--cc=zhangpeng362@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox