From: Andreas Dilger Date: Thu, 25 Jul 2013 22:27:41 +0000 (-0600) Subject: LU-3642 seq: make seq_proc_write_common() safer X-Git-Tag: 2.5.0~50 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=05f69f5ee20eeffcc26f643333cedcfb53ba6669 LU-3642 seq: make seq_proc_write_common() safer Don't allow seq_proc_write_common() to specify arbitrary ranges, since this can permanently corrupt the sequence controller and/or sequnece server. That would allow duplicate FID allocation, or possibly prevent any new files to be created or servers to be added to the filesystem. Instead, limit the sequence range that can be written via /proc to a subset of the sequence range currently allocated to that node. Add the "clear" keyword to allow dropping the entire local sequence and force a new one to be fetched from the sequence server. Signed-off-by: Andreas Dilger Change-Id: I89da0223a52ce8bec787b1d5099402c84274291a Reviewed-on: http://review.whamcloud.com/7123 Reviewed-by: Jinshan Xiong Reviewed-by: Alex Zhuravlev Tested-by: Hudson Reviewed-by: James Simmons Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/fid/lproc_fid.c b/lustre/fid/lproc_fid.c index 7d70870..de7a5cb 100644 --- a/lustre/fid/lproc_fid.c +++ b/lustre/fid/lproc_fid.c @@ -53,16 +53,19 @@ #include #ifdef LPROCFS -/* - * Note: this function is only used for testing, it is no safe for production - * use. +/** + * Reduce the SEQ range allocated to a node to a strict subset of the range + * currently-allocated SEQ range. If the specified range is "clear", then + * drop all allocated sequences and request a new one from the master. + * + * Note: this function should only be used for testing, it is not necessarily + * safe for production use. */ -static int -seq_proc_write_common(struct file *file, const char *buffer, - unsigned long count, void *data, - struct lu_seq_range *range) +static int seq_proc_write_common(struct file *file, const char *buffer, + unsigned long count, void *data, + struct lu_seq_range *range) { - struct lu_seq_range tmp; + struct lu_seq_range tmp = { 0, }; int rc; ENTRY; @@ -73,24 +76,25 @@ seq_proc_write_common(struct file *file, const char *buffer, RETURN(0); } - rc = sscanf(buffer, "[%llx - %llx]\n", - (long long unsigned *)&tmp.lsr_start, - (long long unsigned *)&tmp.lsr_end); - if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp)) + /* of the form "[0x0000000240000400 - 0x000000028000400]" */ + rc = sscanf(buffer, "[%llx - %llx]\n", + (long long unsigned *)&tmp.lsr_start, + (long long unsigned *)&tmp.lsr_end); + if (!range_is_sane(&tmp) || range_is_zero(&tmp) || + tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end) RETURN(-EINVAL); *range = tmp; - RETURN(0); + RETURN(0); } -static int -seq_proc_read_common(char *page, char **start, off_t off, - int count, int *eof, void *data, - struct lu_seq_range *range) +static int seq_proc_read_common(char *page, char **start, off_t off, + int count, int *eof, void *data, + struct lu_seq_range *range) { int rc; ENTRY; - *eof = 1; + *eof = 1; rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%s\n", PRANGE(range)); RETURN(rc); diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h index 45fe409..9271c00 100644 --- a/lustre/include/lustre/lustre_idl.h +++ b/lustre/include/lustre/lustre_idl.h @@ -264,7 +264,7 @@ static inline __u64 range_space(const struct lu_seq_range *range) static inline void range_init(struct lu_seq_range *range) { - range->lsr_start = range->lsr_end = range->lsr_index = 0; + memset(range, 0, sizeof(*range)); } /**