Skip to content

Commit 9d65be3

Browse files
sandeengregkh
authored andcommitted
xfs: only return -errno or success from attr ->put_listent
commit 2a6fba6d2311151598abaa1e7c9abd5f8d024a43 upstream. Today, the put_listent formatters return either 1 or 0; if they return 1, some callers treat this as an error and return it up the stack, despite "1" not being a valid (negative) error code. The intent seems to be that if the input buffer is full, we set seen_enough or set count = -1, and return 1; but some callers check the return before checking the seen_enough or count fields of the context. Fix this by only returning non-zero for actual errors encountered, and rely on the caller to first check the return value, then check the values in the context to decide what to do. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Dave Chinner <david@fromorbit.com> Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1b03d85 commit 9d65be3

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

fs/xfs/xfs_attr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ typedef struct attrlist_cursor_kern {
112112
*========================================================================*/
113113

114114

115+
/* Return 0 on success, or -errno; other state communicated via *context */
115116
typedef int (*put_listent_func_t)(struct xfs_attr_list_context *, int,
116117
unsigned char *, int, int, unsigned char *);
117118

fs/xfs/xfs_attr_list.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,14 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
108108
(int)sfe->namelen,
109109
(int)sfe->valuelen,
110110
&sfe->nameval[sfe->namelen]);
111-
111+
if (error)
112+
return error;
112113
/*
113114
* Either search callback finished early or
114115
* didn't fit it all in the buffer after all.
115116
*/
116117
if (context->seen_enough)
117118
break;
118-
119-
if (error)
120-
return error;
121119
sfe = XFS_ATTR_SF_NEXTENTRY(sfe);
122120
}
123121
trace_xfs_attr_list_sf_all(context);
@@ -581,7 +579,7 @@ xfs_attr_put_listent(
581579
trace_xfs_attr_list_full(context);
582580
alist->al_more = 1;
583581
context->seen_enough = 1;
584-
return 1;
582+
return 0;
585583
}
586584

587585
aep = (attrlist_ent_t *)&context->alist[context->firstu];

fs/xfs/xfs_xattr.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ xfs_xattr_put_listent(
180180
arraytop = context->count + prefix_len + namelen + 1;
181181
if (arraytop > context->firstu) {
182182
context->count = -1; /* insufficient space */
183-
return 1;
183+
return 0;
184184
}
185185
offset = (char *)context->alist + context->count;
186186
strncpy(offset, xfs_xattr_prefix(flags), prefix_len);
@@ -222,12 +222,15 @@ list_one_attr(const char *name, const size_t len, void *data,
222222
}
223223

224224
ssize_t
225-
xfs_vn_listxattr(struct dentry *dentry, char *data, size_t size)
225+
xfs_vn_listxattr(
226+
struct dentry *dentry,
227+
char *data,
228+
size_t size)
226229
{
227230
struct xfs_attr_list_context context;
228231
struct attrlist_cursor_kern cursor = { 0 };
229-
struct inode *inode = d_inode(dentry);
230-
int error;
232+
struct inode *inode = d_inode(dentry);
233+
int error;
231234

232235
/*
233236
* First read the regular on-disk attributes.
@@ -245,7 +248,9 @@ xfs_vn_listxattr(struct dentry *dentry, char *data, size_t size)
245248
else
246249
context.put_listent = xfs_xattr_put_listent_sizes;
247250

248-
xfs_attr_list_int(&context);
251+
error = xfs_attr_list_int(&context);
252+
if (error)
253+
return error;
249254
if (context.count < 0)
250255
return -ERANGE;
251256

0 commit comments

Comments
 (0)