aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolai Stange <nicstange@gmail.com>2017-10-30 19:15:50 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-11-07 14:25:02 -0500
commit69d29f9e6a53559895e6f785f6cf72daa738f132 (patch)
tree580df37d0e089b4ec16c218540a2b4618864bd06
parent055ab8e3e3d52e005d2047b14ce63551b3a8b8b5 (diff)
debugfs: convert to debugfs_file_get() and -put()
Convert all calls to the now obsolete debugfs_use_file_start() and debugfs_use_file_finish() from the debugfs core itself to the new debugfs_file_get() and debugfs_file_put() API. Fixes: 49d200deaa68 ("debugfs: prevent access to removed files' private data") Signed-off-by: Nicolai Stange <nicstange@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--fs/debugfs/file.c106
1 files changed, 50 insertions, 56 deletions
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 08511678b782..d3a972b45ff0 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -155,15 +155,12 @@ EXPORT_SYMBOL_GPL(debugfs_file_put);
155 155
156static int open_proxy_open(struct inode *inode, struct file *filp) 156static int open_proxy_open(struct inode *inode, struct file *filp)
157{ 157{
158 const struct dentry *dentry = F_DENTRY(filp); 158 struct dentry *dentry = F_DENTRY(filp);
159 const struct file_operations *real_fops = NULL; 159 const struct file_operations *real_fops = NULL;
160 int srcu_idx, r; 160 int r = 0;
161 161
162 r = debugfs_use_file_start(dentry, &srcu_idx); 162 if (debugfs_file_get(dentry))
163 if (r) { 163 return -ENOENT;
164 r = -ENOENT;
165 goto out;
166 }
167 164
168 real_fops = debugfs_real_fops(filp); 165 real_fops = debugfs_real_fops(filp);
169 real_fops = fops_get(real_fops); 166 real_fops = fops_get(real_fops);
@@ -180,7 +177,7 @@ static int open_proxy_open(struct inode *inode, struct file *filp)
180 r = real_fops->open(inode, filp); 177 r = real_fops->open(inode, filp);
181 178
182out: 179out:
183 debugfs_use_file_finish(srcu_idx); 180 debugfs_file_put(dentry);
184 return r; 181 return r;
185} 182}
186 183
@@ -194,16 +191,16 @@ const struct file_operations debugfs_open_proxy_file_operations = {
194#define FULL_PROXY_FUNC(name, ret_type, filp, proto, args) \ 191#define FULL_PROXY_FUNC(name, ret_type, filp, proto, args) \
195static ret_type full_proxy_ ## name(proto) \ 192static ret_type full_proxy_ ## name(proto) \
196{ \ 193{ \
197 const struct dentry *dentry = F_DENTRY(filp); \ 194 struct dentry *dentry = F_DENTRY(filp); \
198 const struct file_operations *real_fops = \ 195 const struct file_operations *real_fops = \
199 debugfs_real_fops(filp); \ 196 debugfs_real_fops(filp); \
200 int srcu_idx; \
201 ret_type r; \ 197 ret_type r; \
202 \ 198 \
203 r = debugfs_use_file_start(dentry, &srcu_idx); \ 199 r = debugfs_file_get(dentry); \
204 if (likely(!r)) \ 200 if (unlikely(r)) \
205 r = real_fops->name(args); \ 201 return r; \
206 debugfs_use_file_finish(srcu_idx); \ 202 r = real_fops->name(args); \
203 debugfs_file_put(dentry); \
207 return r; \ 204 return r; \
208} 205}
209 206
@@ -228,18 +225,15 @@ FULL_PROXY_FUNC(unlocked_ioctl, long, filp,
228static unsigned int full_proxy_poll(struct file *filp, 225static unsigned int full_proxy_poll(struct file *filp,
229 struct poll_table_struct *wait) 226 struct poll_table_struct *wait)
230{ 227{
231 const struct dentry *dentry = F_DENTRY(filp);
232 const struct file_operations *real_fops = debugfs_real_fops(filp); 228 const struct file_operations *real_fops = debugfs_real_fops(filp);
233 int srcu_idx; 229 struct dentry *dentry = F_DENTRY(filp);
234 unsigned int r = 0; 230 unsigned int r = 0;
235 231
236 if (debugfs_use_file_start(dentry, &srcu_idx)) { 232 if (debugfs_file_get(dentry))
237 debugfs_use_file_finish(srcu_idx);
238 return POLLHUP; 233 return POLLHUP;
239 }
240 234
241 r = real_fops->poll(filp, wait); 235 r = real_fops->poll(filp, wait);
242 debugfs_use_file_finish(srcu_idx); 236 debugfs_file_put(dentry);
243 return r; 237 return r;
244} 238}
245 239
@@ -283,16 +277,13 @@ static void __full_proxy_fops_init(struct file_operations *proxy_fops,
283 277
284static int full_proxy_open(struct inode *inode, struct file *filp) 278static int full_proxy_open(struct inode *inode, struct file *filp)
285{ 279{
286 const struct dentry *dentry = F_DENTRY(filp); 280 struct dentry *dentry = F_DENTRY(filp);
287 const struct file_operations *real_fops = NULL; 281 const struct file_operations *real_fops = NULL;
288 struct file_operations *proxy_fops = NULL; 282 struct file_operations *proxy_fops = NULL;
289 int srcu_idx, r; 283 int r = 0;
290 284
291 r = debugfs_use_file_start(dentry, &srcu_idx); 285 if (debugfs_file_get(dentry))
292 if (r) { 286 return -ENOENT;
293 r = -ENOENT;
294 goto out;
295 }
296 287
297 real_fops = debugfs_real_fops(filp); 288 real_fops = debugfs_real_fops(filp);
298 real_fops = fops_get(real_fops); 289 real_fops = fops_get(real_fops);
@@ -330,7 +321,7 @@ free_proxy:
330 kfree(proxy_fops); 321 kfree(proxy_fops);
331 fops_put(real_fops); 322 fops_put(real_fops);
332out: 323out:
333 debugfs_use_file_finish(srcu_idx); 324 debugfs_file_put(dentry);
334 return r; 325 return r;
335} 326}
336 327
@@ -341,13 +332,14 @@ const struct file_operations debugfs_full_proxy_file_operations = {
341ssize_t debugfs_attr_read(struct file *file, char __user *buf, 332ssize_t debugfs_attr_read(struct file *file, char __user *buf,
342 size_t len, loff_t *ppos) 333 size_t len, loff_t *ppos)
343{ 334{
335 struct dentry *dentry = F_DENTRY(file);
344 ssize_t ret; 336 ssize_t ret;
345 int srcu_idx;
346 337
347 ret = debugfs_use_file_start(F_DENTRY(file), &srcu_idx); 338 ret = debugfs_file_get(dentry);
348 if (likely(!ret)) 339 if (unlikely(ret))
349 ret = simple_attr_read(file, buf, len, ppos); 340 return ret;
350 debugfs_use_file_finish(srcu_idx); 341 ret = simple_attr_read(file, buf, len, ppos);
342 debugfs_file_put(dentry);
351 return ret; 343 return ret;
352} 344}
353EXPORT_SYMBOL_GPL(debugfs_attr_read); 345EXPORT_SYMBOL_GPL(debugfs_attr_read);
@@ -355,13 +347,14 @@ EXPORT_SYMBOL_GPL(debugfs_attr_read);
355ssize_t debugfs_attr_write(struct file *file, const char __user *buf, 347ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
356 size_t len, loff_t *ppos) 348 size_t len, loff_t *ppos)
357{ 349{
350 struct dentry *dentry = F_DENTRY(file);
358 ssize_t ret; 351 ssize_t ret;
359 int srcu_idx;
360 352
361 ret = debugfs_use_file_start(F_DENTRY(file), &srcu_idx); 353 ret = debugfs_file_get(dentry);
362 if (likely(!ret)) 354 if (unlikely(ret))
363 ret = simple_attr_write(file, buf, len, ppos); 355 return ret;
364 debugfs_use_file_finish(srcu_idx); 356 ret = simple_attr_write(file, buf, len, ppos);
357 debugfs_file_put(dentry);
365 return ret; 358 return ret;
366} 359}
367EXPORT_SYMBOL_GPL(debugfs_attr_write); 360EXPORT_SYMBOL_GPL(debugfs_attr_write);
@@ -795,14 +788,14 @@ ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
795{ 788{
796 char buf[3]; 789 char buf[3];
797 bool val; 790 bool val;
798 int r, srcu_idx; 791 int r;
792 struct dentry *dentry = F_DENTRY(file);
799 793
800 r = debugfs_use_file_start(F_DENTRY(file), &srcu_idx); 794 r = debugfs_file_get(dentry);
801 if (likely(!r)) 795 if (unlikely(r))
802 val = *(bool *)file->private_data;
803 debugfs_use_file_finish(srcu_idx);
804 if (r)
805 return r; 796 return r;
797 val = *(bool *)file->private_data;
798 debugfs_file_put(dentry);
806 799
807 if (val) 800 if (val)
808 buf[0] = 'Y'; 801 buf[0] = 'Y';
@@ -820,8 +813,9 @@ ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
820 char buf[32]; 813 char buf[32];
821 size_t buf_size; 814 size_t buf_size;
822 bool bv; 815 bool bv;
823 int r, srcu_idx; 816 int r;
824 bool *val = file->private_data; 817 bool *val = file->private_data;
818 struct dentry *dentry = F_DENTRY(file);
825 819
826 buf_size = min(count, (sizeof(buf)-1)); 820 buf_size = min(count, (sizeof(buf)-1));
827 if (copy_from_user(buf, user_buf, buf_size)) 821 if (copy_from_user(buf, user_buf, buf_size))
@@ -829,12 +823,11 @@ ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
829 823
830 buf[buf_size] = '\0'; 824 buf[buf_size] = '\0';
831 if (strtobool(buf, &bv) == 0) { 825 if (strtobool(buf, &bv) == 0) {
832 r = debugfs_use_file_start(F_DENTRY(file), &srcu_idx); 826 r = debugfs_file_get(dentry);
833 if (likely(!r)) 827 if (unlikely(r))
834 *val = bv;
835 debugfs_use_file_finish(srcu_idx);
836 if (r)
837 return r; 828 return r;
829 *val = bv;
830 debugfs_file_put(dentry);
838 } 831 }
839 832
840 return count; 833 return count;
@@ -896,14 +889,15 @@ static ssize_t read_file_blob(struct file *file, char __user *user_buf,
896 size_t count, loff_t *ppos) 889 size_t count, loff_t *ppos)
897{ 890{
898 struct debugfs_blob_wrapper *blob = file->private_data; 891 struct debugfs_blob_wrapper *blob = file->private_data;
892 struct dentry *dentry = F_DENTRY(file);
899 ssize_t r; 893 ssize_t r;
900 int srcu_idx;
901 894
902 r = debugfs_use_file_start(F_DENTRY(file), &srcu_idx); 895 r = debugfs_file_get(dentry);
903 if (likely(!r)) 896 if (unlikely(r))
904 r = simple_read_from_buffer(user_buf, count, ppos, blob->data, 897 return r;
905 blob->size); 898 r = simple_read_from_buffer(user_buf, count, ppos, blob->data,
906 debugfs_use_file_finish(srcu_idx); 899 blob->size);
900 debugfs_file_put(dentry);
907 return r; 901 return r;
908} 902}
909 903