media: stv06xx: add missing descriptor sanity checks
[linux/fpc-iii.git] / fs / squashfs / id.c
blob6be5afe7287d63d80dc1cff0d668065e873525dc
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Squashfs - a compressed read only filesystem for Linux
5 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
6 * Phillip Lougher <phillip@squashfs.org.uk>
8 * id.c
9 */
12 * This file implements code to handle uids and gids.
14 * For space efficiency regular files store uid and gid indexes, which are
15 * converted to 32-bit uids/gids using an id look up table. This table is
16 * stored compressed into metadata blocks. A second index table is used to
17 * locate these. This second index table for speed of access (and because it
18 * is small) is read at mount time and cached in memory.
21 #include <linux/fs.h>
22 #include <linux/vfs.h>
23 #include <linux/slab.h>
25 #include "squashfs_fs.h"
26 #include "squashfs_fs_sb.h"
27 #include "squashfs.h"
30 * Map uid/gid index into real 32-bit uid/gid using the id look up table
32 int squashfs_get_id(struct super_block *sb, unsigned int index,
33 unsigned int *id)
35 struct squashfs_sb_info *msblk = sb->s_fs_info;
36 int block = SQUASHFS_ID_BLOCK(index);
37 int offset = SQUASHFS_ID_BLOCK_OFFSET(index);
38 u64 start_block = le64_to_cpu(msblk->id_table[block]);
39 __le32 disk_id;
40 int err;
42 err = squashfs_read_metadata(sb, &disk_id, &start_block, &offset,
43 sizeof(disk_id));
44 if (err < 0)
45 return err;
47 *id = le32_to_cpu(disk_id);
48 return 0;
53 * Read uncompressed id lookup table indexes from disk into memory
55 __le64 *squashfs_read_id_index_table(struct super_block *sb,
56 u64 id_table_start, u64 next_table, unsigned short no_ids)
58 unsigned int length = SQUASHFS_ID_BLOCK_BYTES(no_ids);
59 __le64 *table;
61 TRACE("In read_id_index_table, length %d\n", length);
63 /* Sanity check values */
65 /* there should always be at least one id */
66 if (no_ids == 0)
67 return ERR_PTR(-EINVAL);
70 * length bytes should not extend into the next table - this check
71 * also traps instances where id_table_start is incorrectly larger
72 * than the next table start
74 if (id_table_start + length > next_table)
75 return ERR_PTR(-EINVAL);
77 table = squashfs_read_table(sb, id_table_start, length);
80 * table[0] points to the first id lookup table metadata block, this
81 * should be less than id_table_start
83 if (!IS_ERR(table) && le64_to_cpu(table[0]) >= id_table_start) {
84 kfree(table);
85 return ERR_PTR(-EINVAL);
88 return table;