aboutsummaryrefslogtreecommitdiffstats
path: root/fs/squashfs/xattr.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/squashfs/xattr.c')
-rw-r--r--fs/squashfs/xattr.c86
1 files changed, 33 insertions, 53 deletions
diff --git a/fs/squashfs/xattr.c b/fs/squashfs/xattr.c
index e5e0ddf5b143..6a4cc344085c 100644
--- a/fs/squashfs/xattr.c
+++ b/fs/squashfs/xattr.c
@@ -68,8 +68,8 @@ ssize_t squashfs_listxattr(struct dentry *d, char *buffer,
68 name_size = le16_to_cpu(entry.size); 68 name_size = le16_to_cpu(entry.size);
69 handler = squashfs_xattr_handler(le16_to_cpu(entry.type)); 69 handler = squashfs_xattr_handler(le16_to_cpu(entry.type));
70 if (handler) 70 if (handler)
71 prefix_size = handler->list(d, buffer, rest, NULL, 71 prefix_size = handler->list(handler, d, buffer, rest,
72 name_size, handler->flags); 72 NULL, name_size);
73 if (prefix_size) { 73 if (prefix_size) {
74 if (buffer) { 74 if (buffer) {
75 if (prefix_size + name_size + 1 > rest) { 75 if (prefix_size + name_size + 1 > rest) {
@@ -212,88 +212,68 @@ failed:
212} 212}
213 213
214 214
215/* 215static size_t squashfs_xattr_handler_list(const struct xattr_handler *handler,
216 * User namespace support 216 struct dentry *d, char *list,
217 */ 217 size_t list_size, const char *name,
218static size_t squashfs_user_list(struct dentry *d, char *list, size_t list_size, 218 size_t name_len)
219 const char *name, size_t name_len, int type)
220{ 219{
221 if (list && XATTR_USER_PREFIX_LEN <= list_size) 220 int len = strlen(handler->prefix);
222 memcpy(list, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); 221
223 return XATTR_USER_PREFIX_LEN; 222 if (list && len <= list_size)
223 memcpy(list, handler->prefix, len);
224 return len;
224} 225}
225 226
226static int squashfs_user_get(struct dentry *d, const char *name, void *buffer, 227static int squashfs_xattr_handler_get(const struct xattr_handler *handler,
227 size_t size, int type) 228 struct dentry *d, const char *name,
229 void *buffer, size_t size)
228{ 230{
229 if (name[0] == '\0') 231 if (name[0] == '\0')
230 return -EINVAL; 232 return -EINVAL;
231 233
232 return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_USER, name, 234 return squashfs_xattr_get(d_inode(d), handler->flags, name,
233 buffer, size); 235 buffer, size);
234} 236}
235 237
238/*
239 * User namespace support
240 */
236static const struct xattr_handler squashfs_xattr_user_handler = { 241static const struct xattr_handler squashfs_xattr_user_handler = {
237 .prefix = XATTR_USER_PREFIX, 242 .prefix = XATTR_USER_PREFIX,
238 .list = squashfs_user_list, 243 .flags = SQUASHFS_XATTR_USER,
239 .get = squashfs_user_get 244 .list = squashfs_xattr_handler_list,
245 .get = squashfs_xattr_handler_get
240}; 246};
241 247
242/* 248/*
243 * Trusted namespace support 249 * Trusted namespace support
244 */ 250 */
245static size_t squashfs_trusted_list(struct dentry *d, char *list, 251static size_t squashfs_trusted_xattr_handler_list(const struct xattr_handler *handler,
246 size_t list_size, const char *name, size_t name_len, int type) 252 struct dentry *d, char *list,
253 size_t list_size, const char *name,
254 size_t name_len)
247{ 255{
248 if (!capable(CAP_SYS_ADMIN)) 256 if (!capable(CAP_SYS_ADMIN))
249 return 0; 257 return 0;
250 258 return squashfs_xattr_handler_list(handler, d, list, list_size, name,
251 if (list && XATTR_TRUSTED_PREFIX_LEN <= list_size) 259 name_len);
252 memcpy(list, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN);
253 return XATTR_TRUSTED_PREFIX_LEN;
254}
255
256static int squashfs_trusted_get(struct dentry *d, const char *name,
257 void *buffer, size_t size, int type)
258{
259 if (name[0] == '\0')
260 return -EINVAL;
261
262 return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_TRUSTED, name,
263 buffer, size);
264} 260}
265 261
266static const struct xattr_handler squashfs_xattr_trusted_handler = { 262static const struct xattr_handler squashfs_xattr_trusted_handler = {
267 .prefix = XATTR_TRUSTED_PREFIX, 263 .prefix = XATTR_TRUSTED_PREFIX,
268 .list = squashfs_trusted_list, 264 .flags = SQUASHFS_XATTR_TRUSTED,
269 .get = squashfs_trusted_get 265 .list = squashfs_trusted_xattr_handler_list,
266 .get = squashfs_xattr_handler_get
270}; 267};
271 268
272/* 269/*
273 * Security namespace support 270 * Security namespace support
274 */ 271 */
275static size_t squashfs_security_list(struct dentry *d, char *list,
276 size_t list_size, const char *name, size_t name_len, int type)
277{
278 if (list && XATTR_SECURITY_PREFIX_LEN <= list_size)
279 memcpy(list, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN);
280 return XATTR_SECURITY_PREFIX_LEN;
281}
282
283static int squashfs_security_get(struct dentry *d, const char *name,
284 void *buffer, size_t size, int type)
285{
286 if (name[0] == '\0')
287 return -EINVAL;
288
289 return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_SECURITY, name,
290 buffer, size);
291}
292
293static const struct xattr_handler squashfs_xattr_security_handler = { 272static const struct xattr_handler squashfs_xattr_security_handler = {
294 .prefix = XATTR_SECURITY_PREFIX, 273 .prefix = XATTR_SECURITY_PREFIX,
295 .list = squashfs_security_list, 274 .flags = SQUASHFS_XATTR_SECURITY,
296 .get = squashfs_security_get 275 .list = squashfs_xattr_handler_list,
276 .get = squashfs_xattr_handler_get
297}; 277};
298 278
299static const struct xattr_handler *squashfs_xattr_handler(int type) 279static const struct xattr_handler *squashfs_xattr_handler(int type)