linux/fs/xfs/xfs_ioctl.h
Dan Carpenter 44addae95e xfs: prevent a WARN_ONCE() in xfs_ioc_attr_list()
[ Upstream commit 6ed6356b07 ]

The "bufsize" comes from the root user.  If "bufsize" is negative then,
because of type promotion, neither of the validation checks at the start
of the function are able to catch it:

	if (bufsize < sizeof(struct xfs_attrlist) ||
	    bufsize > XFS_XATTR_LIST_MAX)
		return -EINVAL;

This means "bufsize" will trigger (WARN_ON_ONCE(size > INT_MAX)) in
kvmalloc_node().  Fix this by changing the type from int to size_t.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Leah Rumancik <leah.rumancik@gmail.com>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-07-29 17:25:09 +02:00

79 lines
1.5 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2008 Silicon Graphics, Inc.
* All Rights Reserved.
*/
#ifndef __XFS_IOCTL_H__
#define __XFS_IOCTL_H__
struct xfs_bstat;
struct xfs_ibulk;
struct xfs_inogrp;
extern int
xfs_ioc_space(
struct file *filp,
xfs_flock64_t *bf);
int
xfs_ioc_swapext(
xfs_swapext_t *sxp);
extern int
xfs_find_handle(
unsigned int cmd,
xfs_fsop_handlereq_t *hreq);
extern int
xfs_open_by_handle(
struct file *parfilp,
xfs_fsop_handlereq_t *hreq);
extern int
xfs_readlink_by_handle(
struct file *parfilp,
xfs_fsop_handlereq_t *hreq);
int xfs_ioc_attrmulti_one(struct file *parfilp, struct inode *inode,
uint32_t opcode, void __user *uname, void __user *value,
uint32_t *len, uint32_t flags);
int xfs_ioc_attr_list(struct xfs_inode *dp, void __user *ubuf,
size_t bufsize, int flags,
struct xfs_attrlist_cursor __user *ucursor);
extern struct dentry *
xfs_handle_to_dentry(
struct file *parfilp,
void __user *uhandle,
u32 hlen);
extern int
xfs_fileattr_get(
struct dentry *dentry,
struct fileattr *fa);
extern int
xfs_fileattr_set(
struct user_namespace *mnt_userns,
struct dentry *dentry,
struct fileattr *fa);
extern long
xfs_file_ioctl(
struct file *filp,
unsigned int cmd,
unsigned long p);
extern long
xfs_file_compat_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg);
int xfs_fsbulkstat_one_fmt(struct xfs_ibulk *breq,
const struct xfs_bulkstat *bstat);
int xfs_fsinumbers_fmt(struct xfs_ibulk *breq, const struct xfs_inumbers *igrp);
#endif