aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/squashfs/xattr.c90
1 files changed, 31 insertions, 59 deletions
diff --git a/fs/squashfs/xattr.c b/fs/squashfs/xattr.c
index 4ae1e4ffd200..6a4cc344085c 100644
--- a/fs/squashfs/xattr.c
+++ b/fs/squashfs/xattr.c
@@ -212,96 +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(const struct xattr_handler *handler, 218 size_t name_len)
219 struct dentry *d, char *list, size_t list_size,
220 const char *name, size_t name_len)
221{ 219{
222 if (list && XATTR_USER_PREFIX_LEN <= list_size) 220 int len = strlen(handler->prefix);
223 memcpy(list, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); 221
224 return XATTR_USER_PREFIX_LEN; 222 if (list && len <= list_size)
223 memcpy(list, handler->prefix, len);
224 return len;
225} 225}
226 226
227static int squashfs_user_get(const struct xattr_handler *handler, 227static int squashfs_xattr_handler_get(const struct xattr_handler *handler,
228 struct dentry *d, const char *name, void *buffer, 228 struct dentry *d, const char *name,
229 size_t size) 229 void *buffer, size_t size)
230{ 230{
231 if (name[0] == '\0') 231 if (name[0] == '\0')
232 return -EINVAL; 232 return -EINVAL;
233 233
234 return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_USER, name, 234 return squashfs_xattr_get(d_inode(d), handler->flags, name,
235 buffer, size); 235 buffer, size);
236} 236}
237 237
238/*
239 * User namespace support
240 */
238static const struct xattr_handler squashfs_xattr_user_handler = { 241static const struct xattr_handler squashfs_xattr_user_handler = {
239 .prefix = XATTR_USER_PREFIX, 242 .prefix = XATTR_USER_PREFIX,
240 .list = squashfs_user_list, 243 .flags = SQUASHFS_XATTR_USER,
241 .get = squashfs_user_get 244 .list = squashfs_xattr_handler_list,
245 .get = squashfs_xattr_handler_get
242}; 246};
243 247
244/* 248/*
245 * Trusted namespace support 249 * Trusted namespace support
246 */ 250 */
247static size_t squashfs_trusted_list(const struct xattr_handler *handler, 251static size_t squashfs_trusted_xattr_handler_list(const struct xattr_handler *handler,
248 struct dentry *d, char *list, 252 struct dentry *d, char *list,
249 size_t list_size, const char *name, 253 size_t list_size, const char *name,
250 size_t name_len) 254 size_t name_len)
251{ 255{
252 if (!capable(CAP_SYS_ADMIN)) 256 if (!capable(CAP_SYS_ADMIN))
253 return 0; 257 return 0;
254 258 return squashfs_xattr_handler_list(handler, d, list, list_size, name,
255 if (list && XATTR_TRUSTED_PREFIX_LEN <= list_size) 259 name_len);
256 memcpy(list, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN);
257 return XATTR_TRUSTED_PREFIX_LEN;
258}
259
260static int squashfs_trusted_get(const struct xattr_handler *handler,
261 struct dentry *d, const char *name,
262 void *buffer, size_t size)
263{
264 if (name[0] == '\0')
265 return -EINVAL;
266
267 return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_TRUSTED, name,
268 buffer, size);
269} 260}
270 261
271static const struct xattr_handler squashfs_xattr_trusted_handler = { 262static const struct xattr_handler squashfs_xattr_trusted_handler = {
272 .prefix = XATTR_TRUSTED_PREFIX, 263 .prefix = XATTR_TRUSTED_PREFIX,
273 .list = squashfs_trusted_list, 264 .flags = SQUASHFS_XATTR_TRUSTED,
274 .get = squashfs_trusted_get 265 .list = squashfs_trusted_xattr_handler_list,
266 .get = squashfs_xattr_handler_get
275}; 267};
276 268
277/* 269/*
278 * Security namespace support 270 * Security namespace support
279 */ 271 */
280static size_t squashfs_security_list(const struct xattr_handler *handler,
281 struct dentry *d, char *list,
282 size_t list_size, const char *name,
283 size_t name_len)
284{
285 if (list && XATTR_SECURITY_PREFIX_LEN <= list_size)
286 memcpy(list, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN);
287 return XATTR_SECURITY_PREFIX_LEN;
288}
289
290static int squashfs_security_get(const struct xattr_handler *handler,
291 struct dentry *d, const char *name,
292 void *buffer, size_t size)
293{
294 if (name[0] == '\0')
295 return -EINVAL;
296
297 return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_SECURITY, name,
298 buffer, size);
299}
300
301static const struct xattr_handler squashfs_xattr_security_handler = { 272static const struct xattr_handler squashfs_xattr_security_handler = {
302 .prefix = XATTR_SECURITY_PREFIX, 273 .prefix = XATTR_SECURITY_PREFIX,
303 .list = squashfs_security_list, 274 .flags = SQUASHFS_XATTR_SECURITY,
304 .get = squashfs_security_get 275 .list = squashfs_xattr_handler_list,
276 .get = squashfs_xattr_handler_get
305}; 277};
306 278
307static const struct xattr_handler *squashfs_xattr_handler(int type) 279static const struct xattr_handler *squashfs_xattr_handler(int type)