Skip to content

Commit b27824d

Browse files
Chaitanya Kulkarniaxboe
Chaitanya Kulkarni
authored andcommitted
loop: use sysfs_emit() in the sysfs xxx show()
sprintf does not know the PAGE_SIZE maximum of the temporary buffer used for outputting sysfs content and it's possible to overrun the PAGE_SIZE buffer length. Use a generic sysfs_emit function that knows the size of the temporary buffer and ensures that no overrun is done for offset attribute in loop_attr_[offset|sizelimit|autoclear|partscan|dio]_show() callbacks. Signed-off-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Himanshu Madhani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent a75110c commit b27824d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/block/loop.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,33 +680,33 @@ static ssize_t loop_attr_backing_file_show(struct loop_device *lo, char *buf)
680680

681681
static ssize_t loop_attr_offset_show(struct loop_device *lo, char *buf)
682682
{
683-
return sprintf(buf, "%llu\n", (unsigned long long)lo->lo_offset);
683+
return sysfs_emit(buf, "%llu\n", (unsigned long long)lo->lo_offset);
684684
}
685685

686686
static ssize_t loop_attr_sizelimit_show(struct loop_device *lo, char *buf)
687687
{
688-
return sprintf(buf, "%llu\n", (unsigned long long)lo->lo_sizelimit);
688+
return sysfs_emit(buf, "%llu\n", (unsigned long long)lo->lo_sizelimit);
689689
}
690690

691691
static ssize_t loop_attr_autoclear_show(struct loop_device *lo, char *buf)
692692
{
693693
int autoclear = (lo->lo_flags & LO_FLAGS_AUTOCLEAR);
694694

695-
return sprintf(buf, "%s\n", autoclear ? "1" : "0");
695+
return sysfs_emit(buf, "%s\n", autoclear ? "1" : "0");
696696
}
697697

698698
static ssize_t loop_attr_partscan_show(struct loop_device *lo, char *buf)
699699
{
700700
int partscan = (lo->lo_flags & LO_FLAGS_PARTSCAN);
701701

702-
return sprintf(buf, "%s\n", partscan ? "1" : "0");
702+
return sysfs_emit(buf, "%s\n", partscan ? "1" : "0");
703703
}
704704

705705
static ssize_t loop_attr_dio_show(struct loop_device *lo, char *buf)
706706
{
707707
int dio = (lo->lo_flags & LO_FLAGS_DIRECT_IO);
708708

709-
return sprintf(buf, "%s\n", dio ? "1" : "0");
709+
return sysfs_emit(buf, "%s\n", dio ? "1" : "0");
710710
}
711711

712712
LOOP_ATTR_RO(backing_file);

0 commit comments

Comments
 (0)