Skip to content

Commit d617ef0

Browse files
keesebiggers
authored andcommitted
fscrypt: Replace 1-element array with flexible array
1-element arrays are deprecated and are being replaced with C99 flexible arrays[1]. As sizes were being calculated with the extra byte intentionally, propagate the difference so there is no change in binary output. [1] KSPP#79 Cc: Eric Biggers <[email protected]> Cc: "Theodore Y. Ts'o" <[email protected]> Cc: Jaegeuk Kim <[email protected]> Cc: Gustavo A. R. Silva <[email protected]> Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 44c026a commit d617ef0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

fs/crypto/fscrypt_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fscrypt_policy_flags(const union fscrypt_policy *policy)
171171
*/
172172
struct fscrypt_symlink_data {
173173
__le16 len;
174-
char encrypted_path[1];
174+
char encrypted_path[];
175175
} __packed;
176176

177177
/**

fs/crypto/hooks.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ int fscrypt_prepare_symlink(struct inode *dir, const char *target,
255255
* for now since filesystems will assume it is there and subtract it.
256256
*/
257257
if (!__fscrypt_fname_encrypted_size(policy, len,
258-
max_len - sizeof(struct fscrypt_symlink_data),
258+
max_len - sizeof(struct fscrypt_symlink_data) - 1,
259259
&disk_link->len))
260260
return -ENAMETOOLONG;
261-
disk_link->len += sizeof(struct fscrypt_symlink_data);
261+
disk_link->len += sizeof(struct fscrypt_symlink_data) + 1;
262262

263263
disk_link->name = NULL;
264264
return 0;
@@ -289,7 +289,7 @@ int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
289289
if (!sd)
290290
return -ENOMEM;
291291
}
292-
ciphertext_len = disk_link->len - sizeof(*sd);
292+
ciphertext_len = disk_link->len - sizeof(*sd) - 1;
293293
sd->len = cpu_to_le16(ciphertext_len);
294294

295295
err = fscrypt_fname_encrypt(inode, &iname, sd->encrypted_path,
@@ -367,7 +367,7 @@ const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
367367
* the ciphertext length, even though this is redundant with i_size.
368368
*/
369369

370-
if (max_size < sizeof(*sd))
370+
if (max_size < sizeof(*sd) + 1)
371371
return ERR_PTR(-EUCLEAN);
372372
sd = caddr;
373373
cstr.name = (unsigned char *)sd->encrypted_path;
@@ -376,7 +376,7 @@ const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
376376
if (cstr.len == 0)
377377
return ERR_PTR(-EUCLEAN);
378378

379-
if (cstr.len + sizeof(*sd) - 1 > max_size)
379+
if (cstr.len + sizeof(*sd) > max_size)
380380
return ERR_PTR(-EUCLEAN);
381381

382382
err = fscrypt_fname_alloc_buffer(cstr.len, &pstr);

0 commit comments

Comments
 (0)