Skip to content

Commit 2869b3a

Browse files
tobluxchucklever
authored andcommitted
NFSD: Annotate struct pnfs_block_deviceaddr with __counted_by()
Add the __counted_by compiler attribute to the flexible array member volumes to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE. Use struct_size() instead of manually calculating the number of bytes to allocate for a pnfs_block_deviceaddr with a single volume. Signed-off-by: Thorsten Blum <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Acked-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent d078cbf commit 2869b3a

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

fs/nfsd/blocklayout.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ nfsd4_block_get_device_info_simple(struct super_block *sb,
147147
struct pnfs_block_deviceaddr *dev;
148148
struct pnfs_block_volume *b;
149149

150-
dev = kzalloc(sizeof(struct pnfs_block_deviceaddr) +
151-
sizeof(struct pnfs_block_volume), GFP_KERNEL);
150+
dev = kzalloc(struct_size(dev, volumes, 1), GFP_KERNEL);
152151
if (!dev)
153152
return -ENOMEM;
154153
gdp->gd_device = dev;
@@ -255,8 +254,7 @@ nfsd4_block_get_device_info_scsi(struct super_block *sb,
255254
const struct pr_ops *ops;
256255
int ret;
257256

258-
dev = kzalloc(sizeof(struct pnfs_block_deviceaddr) +
259-
sizeof(struct pnfs_block_volume), GFP_KERNEL);
257+
dev = kzalloc(struct_size(dev, volumes, 1), GFP_KERNEL);
260258
if (!dev)
261259
return -ENOMEM;
262260
gdp->gd_device = dev;

fs/nfsd/blocklayoutxdr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct pnfs_block_volume {
4747

4848
struct pnfs_block_deviceaddr {
4949
u32 nr_volumes;
50-
struct pnfs_block_volume volumes[];
50+
struct pnfs_block_volume volumes[] __counted_by(nr_volumes);
5151
};
5252

5353
__be32 nfsd4_block_encode_getdeviceinfo(struct xdr_stream *xdr,

0 commit comments

Comments
 (0)