#include <md_object.h>
#ifdef LPROCFS
+
+/* Format: [0x64BIT_INT - 0x64BIT_INT] + 32 bytes just in case */
+#define MAX_FID_RANGE_STRLEN (32 + 2 * 2 * sizeof(__u64))
/**
* 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
* safe for production use.
*/
static int
-lprocfs_fid_write_common(const char *buffer, unsigned long count,
+lprocfs_fid_write_common(const char __user *buffer, size_t count,
struct lu_seq_range *range)
{
struct lu_seq_range tmp = { 0, };
int rc;
+ char kernbuf[MAX_FID_RANGE_STRLEN];
ENTRY;
LASSERT(range != NULL);
- if (count == 5 && strcmp(buffer, "clear") == 0) {
+ if (count >= sizeof(kernbuf))
+ RETURN(-EINVAL);
+
+ if (copy_from_user(kernbuf, buffer, count))
+ RETURN(-EFAULT);
+
+ kernbuf[count] = 0;
+
+ if (count == 5 && strcmp(kernbuf, "clear") == 0) {
memset(range, 0, sizeof(*range));
RETURN(0);
}
/* of the form "[0x0000000240000400 - 0x000000028000400]" */
- rc = sscanf(buffer, "[%llx - %llx]\n",
+ rc = sscanf(kernbuf, "[%llx - %llx]\n",
(long long unsigned *)&tmp.lsr_start,
(long long unsigned *)&tmp.lsr_end);
if (!range_is_sane(&tmp) || range_is_zero(&tmp) ||
* Server side procfs stuff.
*/
static ssize_t
-lprocfs_server_fid_space_seq_write(struct file *file, const char *buffer,
+lprocfs_server_fid_space_seq_write(struct file *file, const char __user *buffer,
size_t count, loff_t *off)
{
struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
}
static ssize_t
-lprocfs_server_fid_width_seq_write(struct file *file, const char *buffer,
+lprocfs_server_fid_width_seq_write(struct file *file, const char __user *buffer,
size_t count, loff_t *off)
{
struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
return 0;
}
-static ssize_t fldb_seq_write(struct file *file, const char *buf,
+static ssize_t fldb_seq_write(struct file *file, const char __user *buf,
size_t len, loff_t *off)
{
struct seq_file *seq = file->private_data;
struct fld_seq_param *param;
struct lu_seq_range range;
int rc = 0;
- char *buffer, *_buffer;
+ char _buffer[MAX_FID_RANGE_STRLEN];
+ char *buffer = _buffer;
ENTRY;
param = seq->private;
if (param == NULL)
RETURN(-EINVAL);
- OBD_ALLOC(buffer, len + 1);
- if (buffer == NULL)
- RETURN(-ENOMEM);
- memcpy(buffer, buf, len);
+ if (len >= sizeof(_buffer))
+ RETURN(-EINVAL);
+
+ if (copy_from_user(buffer, buf, len))
+ GOTO(out, rc = -EFAULT);
buffer[len] = 0;
- _buffer = buffer;
/*
* format - [0x0000000200000007-0x0000000200000008):0:mdt
&range, ¶m->fsp_env);
out:
- OBD_FREE(_buffer, len + 1);
RETURN(rc < 0 ? rc : len);
}
/* Client side procfs stuff */
static ssize_t
-lprocfs_client_fid_space_seq_write(struct file *file, const char *buffer,
+lprocfs_client_fid_space_seq_write(struct file *file, const char __user *buffer,
size_t count, loff_t *off)
{
struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
}
static ssize_t
-lprocfs_client_fid_width_seq_write(struct file *file, const char *buffer,
+lprocfs_client_fid_width_seq_write(struct file *file, const char __user *buffer,
size_t count, loff_t *off)
{
struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
}
static ssize_t
-ll_max_cached_mb_seq_write(struct file *file, const char *buffer,
+ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
size_t count, loff_t *off)
{
struct seq_file *m = file->private_data;
int mult, rc, pages_number;
int diff = 0;
int nrpages = 0;
+ char kernbuf[128];
ENTRY;
+ if (count >= sizeof(kernbuf))
+ RETURN(-EINVAL);
+
+ if (copy_from_user(kernbuf, buffer, count))
+ RETURN(-EFAULT);
+ kernbuf[count] = 0;
+
mult = 1 << (20 - PAGE_CACHE_SHIFT);
- buffer = lprocfs_find_named_value(buffer, "max_cached_mb:", &count);
+ buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
+ kernbuf;
rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
if (rc)
RETURN(rc);
}
static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
- const char *buf, size_t len,
- loff_t *off)
+ const char __user *buf,
+ size_t len,
+ loff_t *off)
{
- struct seq_file *seq = file->private_data;
- struct ll_sb_info *sbi = seq->private;
- struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
- int i;
- int value = 1, rc = 0;
+ struct seq_file *seq = file->private_data;
+ struct ll_sb_info *sbi = seq->private;
+ struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
+ int i;
+ int value = 1, rc = 0;
- rc = lprocfs_write_helper(buf, len, &value);
- if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
- strcmp(buf, "Disabled") == 0))
- value = 0;
+ if (len == 0)
+ return -EINVAL;
- if (value == 0)
- sbi->ll_rw_stats_on = 0;
- else
- sbi->ll_rw_stats_on = 1;
+ rc = lprocfs_write_helper(buf, len, &value);
+ if (rc < 0 && len < 16) {
+ char kernbuf[16];
+
+ if (copy_from_user(kernbuf, buf, len))
+ return -EFAULT;
+ kernbuf[len] = 0;
+
+ if (kernbuf[len - 1] == '\n')
+ kernbuf[len - 1] = 0;
+
+ if (strcmp(kernbuf, "disabled") == 0 ||
+ strcmp(kernbuf, "Disabled") == 0)
+ value = 0;
+ }
+
+ if (value == 0)
+ sbi->ll_rw_stats_on = 0;
+ else
+ sbi->ll_rw_stats_on = 1;
spin_lock(&sbi->ll_pp_extent_lock);
for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
return 0;
}
-static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
- size_t len, loff_t *off)
+static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
+ const char __user *buf,
+ size_t len, loff_t *off)
{
- struct seq_file *seq = file->private_data;
- struct ll_sb_info *sbi = seq->private;
- struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
- int i;
- int value = 1, rc = 0;
+ struct seq_file *seq = file->private_data;
+ struct ll_sb_info *sbi = seq->private;
+ struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
+ int i;
+ int value = 1, rc = 0;
- rc = lprocfs_write_helper(buf, len, &value);
- if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
- strcmp(buf, "Disabled") == 0))
- value = 0;
+ if (len == 0)
+ return -EINVAL;
+
+ rc = lprocfs_write_helper(buf, len, &value);
+ if (rc < 0 && len < 16) {
+ char kernbuf[16];
+
+ if (copy_from_user(kernbuf, buf, len))
+ return -EFAULT;
+ kernbuf[len] = 0;
+
+ if (kernbuf[len - 1] == '\n')
+ kernbuf[len - 1] = 0;
+
+ if (strcmp(kernbuf, "disabled") == 0 ||
+ strcmp(kernbuf, "Disabled") == 0)
+ value = 0;
+ }
+
+ if (value == 0)
+ sbi->ll_rw_stats_on = 0;
+ else
+ sbi->ll_rw_stats_on = 1;
- if (value == 0)
- sbi->ll_rw_stats_on = 0;
- else
- sbi->ll_rw_stats_on = 1;
spin_lock(&sbi->ll_pp_extent_lock);
for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
io_extents->pp_extents[i].pid = 0;
return len;
}
-
LPROC_SEQ_FOPS(ll_rw_extents_stats);
void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
return 0;
}
-static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
- size_t len, loff_t *off)
+static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
+ const char __user *buf,
+ size_t len, loff_t *off)
{
- struct seq_file *seq = file->private_data;
- struct ll_sb_info *sbi = seq->private;
- struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
- struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
- int value = 1, rc = 0;
+ struct seq_file *seq = file->private_data;
+ struct ll_sb_info *sbi = seq->private;
+ struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
+ struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
+ int value = 1, rc = 0;
- rc = lprocfs_write_helper(buf, len, &value);
+ if (len == 0)
+ return -EINVAL;
- if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
- strcmp(buf, "Disabled") == 0))
- value = 0;
+ rc = lprocfs_write_helper(buf, len, &value);
- if (value == 0)
- sbi->ll_rw_stats_on = 0;
- else
- sbi->ll_rw_stats_on = 1;
+ if (rc < 0 && len < 16) {
+ char kernbuf[16];
+
+ if (copy_from_user(kernbuf, buf, len))
+ return -EFAULT;
+ kernbuf[len] = 0;
+
+ if (kernbuf[len - 1] == '\n')
+ kernbuf[len - 1] = 0;
+
+ if (strcmp(kernbuf, "disabled") == 0 ||
+ strcmp(kernbuf, "Disabled") == 0)
+ value = 0;
+ }
+
+ if (value == 0)
+ sbi->ll_rw_stats_on = 0;
+ else
+ sbi->ll_rw_stats_on = 1;
spin_lock(&sbi->ll_process_lock);
sbi->ll_offset_process_count = 0;
#define CDT_DISABLE_CMD "disabled"
#define CDT_PURGE_CMD "purge"
#define CDT_HELP_CMD "help"
+#define CDT_MAX_CMD_LEN 10
-int lprocfs_wr_hsm_cdt_control(struct file *file, const char *buffer,
+int lprocfs_wr_hsm_cdt_control(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
struct coordinator *cdt = &(mdt->mdt_coordinator);
int rc, usage = 0;
+ char kernbuf[CDT_MAX_CMD_LEN];
ENTRY;
+ if (count == 0 || count >= sizeof(kernbuf))
+ RETURN(-EINVAL);
+
+ if (copy_from_user(kernbuf, buffer, count))
+ RETURN(-EFAULT);
+ kernbuf[count] = 0;
+
+ if (kernbuf[count - 1] == '\n')
+ kernbuf[count - 1] = 0;
+
rc = 0;
- if (strncmp(buffer, CDT_ENABLE_CMD, strlen(CDT_ENABLE_CMD)) == 0) {
+ if (strcmp(kernbuf, CDT_ENABLE_CMD) == 0) {
if (cdt->cdt_state == CDT_DISABLE) {
cdt->cdt_state = CDT_RUNNING;
mdt_hsm_cdt_wakeup(mdt);
} else {
rc = mdt_hsm_cdt_start(mdt);
}
- } else if (strncmp(buffer, CDT_STOP_CMD, strlen(CDT_STOP_CMD)) == 0) {
+ } else if (strcmp(kernbuf, CDT_STOP_CMD) == 0) {
if ((cdt->cdt_state == CDT_STOPPING) ||
(cdt->cdt_state == CDT_STOPPED)) {
CERROR("%s: Coordinator already stopped\n",
} else {
cdt->cdt_state = CDT_STOPPING;
}
- } else if (strncmp(buffer, CDT_DISABLE_CMD,
- strlen(CDT_DISABLE_CMD)) == 0) {
+ } else if (strcmp(kernbuf, CDT_DISABLE_CMD) == 0) {
if ((cdt->cdt_state == CDT_STOPPING) ||
(cdt->cdt_state == CDT_STOPPED)) {
CERROR("%s: Coordinator is stopped\n",
} else {
cdt->cdt_state = CDT_DISABLE;
}
- } else if (strncmp(buffer, CDT_PURGE_CMD, strlen(CDT_PURGE_CMD)) == 0) {
+ } else if (strcmp(kernbuf, CDT_PURGE_CMD) == 0) {
rc = hsm_cancel_all_actions(mdt);
- } else if (strncmp(buffer, CDT_HELP_CMD, strlen(CDT_HELP_CMD)) == 0) {
+ } else if (strcmp(kernbuf, CDT_HELP_CMD) == 0) {
usage = 1;
} else {
usage = 1;
mdt->mdt_identity_cache->uc_entry_expire);
}
-static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
- unsigned long count, void *data)
+static int lprocfs_wr_identity_expire(struct file *file,
+ const char __user *buffer,
+ unsigned long count, void *data)
{
struct obd_device *obd = data;
struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
}
static int lprocfs_wr_identity_acquire_expire(struct file *file,
- const char *buffer,
- unsigned long count,
- void *data)
+ const char __user *buffer,
+ unsigned long count,
+ void *data)
{
struct obd_device *obd = data;
struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
return len;
}
-static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
+static int lprocfs_wr_identity_upcall(struct file *file,
+ const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
RETURN(rc);
}
-static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,
- unsigned long count, void *data)
+static int lprocfs_wr_identity_flush(struct file *file,
+ const char __user *buffer,
+ unsigned long count, void *data)
{
struct obd_device *obd = data;
struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
return count;
}
-static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
+static int lprocfs_wr_identity_info(struct file *file,
+ const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
mdt->mdt_lut.lut_mds_capa ? "mds" : "");
}
-static int lprocfs_wr_capa(struct file *file, const char *buffer,
+static int lprocfs_wr_capa(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
return snprintf(page, count, "%lu\n", mdt->mdt_capa_timeout);
}
-static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
- unsigned long count, void *data)
+static int lprocfs_wr_capa_timeout(struct file *file, const char __user *buffer,
+ unsigned long count, void *data)
{
struct obd_device *obd = data;
struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
return snprintf(page, count, "%lu\n", mdt->mdt_ck_timeout);
}
-static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
- unsigned long count, void *data)
+static int lprocfs_wr_ck_timeout(struct file *file, const char __user *buffer,
+ unsigned long count, void *data)
{
struct obd_device *obd = data;
struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
#define BUFLEN (UUID_MAX + 4)
-static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
- unsigned long count, void *data)
+static int lprocfs_mdt_wr_evict_client(struct file *file,
+ const char __user *buffer,
+ unsigned long count, void *data)
{
char *kbuf;
char *tmpbuf;
return snprintf(page, count, "%d\n", mdt->mdt_lut.lut_sec_level);
}
-static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
- unsigned long count, void *data)
+static int lprocfs_wr_sec_level(struct file *file, const char __user *buffer,
+ unsigned long count, void *data)
{
struct obd_device *obd = data;
struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
return snprintf(page, count, "%u\n", mdt_cos_is_enabled(mdt));
}
-static int lprocfs_wr_cos(struct file *file, const char *buffer,
- unsigned long count, void *data)
+static int lprocfs_wr_cos(struct file *file, const char __user *buffer,
+ unsigned long count, void *data)
{
struct obd_device *obd = data;
struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
return 0;
}
-static int lprocfs_wr_root_squash(struct file *file, const char *buffer,
+static int lprocfs_wr_root_squash(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
int rc;
- char kernbuf[50], *tmp, *end, *errmsg;
+ char kernbuf[64], *tmp, *end, *errmsg;
unsigned long uid, gid;
int nouid, nogid;
ENTRY;
if (count >= sizeof(kernbuf)) {
errmsg = "string too long";
- GOTO(failed, rc = -EINVAL);
+ GOTO(failed_noprint, rc = -EINVAL);
}
if (copy_from_user(kernbuf, buffer, count)) {
errmsg = "bad address";
- GOTO(failed, rc = -EFAULT);
+ GOTO(failed_noprint, rc = -EFAULT);
}
kernbuf[count] = '\0';
nouid = nogid = 0;
- if (safe_strtoul(buffer, &tmp, &uid)) {
+ if (safe_strtoul(kernbuf, &tmp, &uid)) {
uid = mdt->mdt_squash_uid;
nouid = 1;
}
failed:
CWARN("%s: failed to set root_squash to \"%s\", %s: rc %d\n",
- mdt_obd_name(mdt), buffer, errmsg, rc);
+ mdt_obd_name(mdt), kernbuf, errmsg, rc);
+ RETURN(rc);
+failed_noprint:
+ CWARN("%s: failed to set root_squash due to %s: rc %d\n",
+ mdt_obd_name(mdt), errmsg, rc);
RETURN(rc);
}
return snprintf(page, count, "NONE\n");
}
-static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
+static int lprocfs_wr_nosquash_nids(struct file *file,
+ const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
mdt->mdt_som_conf ? "en" : "dis");
}
-static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
- unsigned long count, void *data)
+static int lprocfs_wr_mdt_som(struct file *file, const char __user *buffer,
+ unsigned long count, void *data)
{
struct obd_export *exp;
struct obd_device *obd = data;
return snprintf(page, count, "%u\n", mdt->mdt_enable_remote_dir);
}
-static int lprocfs_wr_enable_remote_dir(struct file *file, const char *buffer,
+static int lprocfs_wr_enable_remote_dir(struct file *file,
+ const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
}
static int lprocfs_wr_enable_remote_dir_gid(struct file *file,
- const char *buffer,
+ const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
void mgs_ir_notify_complete(struct fs_db *fsdb);
int mgs_get_ir_logs(struct ptlrpc_request *req);
int lprocfs_wr_ir_state(struct file *file, const char *buffer,
- unsigned long count, void *data);
+ size_t count, void *data);
int lprocfs_rd_ir_state(struct seq_file *seq, void *data);
ssize_t
lprocfs_ir_timeout_seq_write(struct file *file, const char *buffer,
{ "0", 1, lprocfs_ir_clear_stats }
};
-int lprocfs_wr_ir_state(struct file *file, const char *buffer,
- unsigned long count, void *data)
+int lprocfs_wr_ir_state(struct file *file, const char __user *buffer,
+ size_t count, void *data)
{
struct fs_db *fsdb = data;
char *kbuf;
char *ptr;
int rc = 0;
- if (count > PAGE_CACHE_SIZE)
- return -EINVAL;
+ if (count == 0 || count >= PAGE_CACHE_SIZE)
+ return -EINVAL;
- OBD_ALLOC(kbuf, count + 1);
- if (kbuf == NULL)
- return -ENOMEM;
+ OBD_ALLOC(kbuf, count + 1);
+ if (kbuf == NULL)
+ return -ENOMEM;
- if (copy_from_user(kbuf, buffer, count)) {
- OBD_FREE(kbuf, count);
- return -EFAULT;
- }
+ if (copy_from_user(kbuf, buffer, count)) {
+ OBD_FREE(kbuf, count + 1);
+ return -EFAULT;
+ }
kbuf[count] = 0; /* buffer is supposed to end with 0 */
if (kbuf[count - 1] == '\n')
return lprocfs_uint_seq_show(m, &ir_timeout);
}
-ssize_t
-lprocfs_ir_timeout_seq_write(struct file *file, const char *buffer,
- size_t count, loff_t *off)
+ssize_t lprocfs_ir_timeout_seq_write(struct file *file,
+ const char __user *buffer,
+ size_t count, loff_t *off)
{
return lprocfs_wr_uint(file, buffer, count, &ir_timeout);
}
}
static ssize_t
-obd_proc_jobid_var_seq_write(struct file *file, const char *buffer,
- size_t count, loff_t *off)
+obd_proc_jobid_var_seq_write(struct file *file, const char __user *buffer,
+ size_t count, loff_t *off)
{
if (!count || count > JOBSTATS_JOBID_VAR_MAX_LEN)
return -EINVAL;
memset(obd_jobid_var, 0, JOBSTATS_JOBID_VAR_MAX_LEN + 1);
+
+ /* This might leave the var invalid on error, which is probably fine.*/
+ if (copy_from_user(obd_jobid_var, buffer, count))
+ return -EFAULT;
+
/* Trim the trailing '\n' if any */
- memcpy(obd_jobid_var, buffer, count - (buffer[count - 1] == '\n'));
+ if (obd_jobid_var[count - 1] == '\n')
+ obd_jobid_var[count - 1] = 0;
+
return count;
}
LPROC_SEQ_FOPS(obd_proc_jobid_var);
return 0;
}
-static ssize_t lprocfs_jobstats_seq_write(struct file *file, const char *buf,
+static ssize_t lprocfs_jobstats_seq_write(struct file *file,
+ const char __user *buf,
size_t len, loff_t *off)
{
struct seq_file *seq = file->private_data;
int all = 0;
struct job_stat *job;
- if (!memcmp(buf, "clear", strlen("clear"))) {
- all = 1;
- } else if (len < JOBSTATS_JOBID_SIZE) {
- memset(jobid, 0, JOBSTATS_JOBID_SIZE);
- /* Trim '\n' if any */
- if (buf[len - 1] == '\n')
- memcpy(jobid, buf, len - 1);
- else
- memcpy(jobid, buf, len);
- } else {
+ if (len == 0 || len >= JOBSTATS_JOBID_SIZE)
return -EINVAL;
- }
+
+ if (copy_from_user(jobid, buf, len))
+ return -EFAULT;
+ jobid[len] = 0;
+
+ /* Trim '\n' if any */
+ if (jobid[len - 1] == '\n')
+ jobid[len - 1] = 0;
+
+ if (strcmp(jobid, "clear") == 0)
+ all = 1;
LASSERT(stats->ojs_hash);
if (all) {
}
EXPORT_SYMBOL(lprocfs_rd_job_interval);
-int lprocfs_wr_job_interval(struct file *file, const char *buffer,
+int lprocfs_wr_job_interval(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = (struct obd_device *)data;
#define BUFLEN (UUID_MAX + 5)
#ifndef HAVE_ONLY_PROCFS_SEQ
-int lprocfs_wr_evict_client(struct file *file, const char *buffer,
+int lprocfs_wr_evict_client(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
(int) ofd_grant_reserved(ofd, 100));
}
-static int lprocfs_ofd_wr_grant_ratio(struct file *file, const char *buffer,
+static int lprocfs_ofd_wr_grant_ratio(struct file *file,
+ const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = (struct obd_device *)data;
return snprintf(page, count, "%d\n", ofd->ofd_precreate_batch);
}
-static int lprocfs_ofd_wr_precreate_batch(struct file *file, const char *buffer,
+static int lprocfs_ofd_wr_precreate_batch(struct file *file,
+ const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = (struct obd_device *)data;
return rc;
}
-int lprocfs_ofd_wr_fmd_max_num(struct file *file, const char *buffer,
+int lprocfs_ofd_wr_fmd_max_num(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
return rc;
}
-int lprocfs_ofd_wr_fmd_max_age(struct file *file, const char *buffer,
+int lprocfs_ofd_wr_fmd_max_age(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
return rc;
}
-static int lprocfs_ofd_wr_capa(struct file *file, const char *buffer,
+static int lprocfs_ofd_wr_capa(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
}
-int lprocfs_ofd_wr_degraded(struct file *file, const char *buffer,
+int lprocfs_ofd_wr_degraded(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
return rc;
}
-int lprocfs_ofd_wr_syncjournal(struct file *file, const char *buffer,
+int lprocfs_ofd_wr_syncjournal(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
return count;
}
+/* This must be longer than the longest string below */
+#define SYNC_STATES_MAXLEN 16
static char *sync_on_cancel_states[] = {"never",
"blocking",
"always" };
return rc;
}
-int lprocfs_ofd_wr_sync_lock_cancel(struct file *file, const char *buffer,
+int lprocfs_ofd_wr_sync_lock_cancel(struct file *file,
+ const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
struct lu_target *tgt = obd->u.obt.obt_lut;
+ char kernbuf[SYNC_STATES_MAXLEN];
int val = -1;
int i;
+ if (count == 0 || count >= sizeof(kernbuf))
+ return -EINVAL;
+
+ if (copy_from_user(kernbuf, buffer, count))
+ return -EFAULT;
+ kernbuf[count] = 0;
+
+ if (kernbuf[count - 1] == '\n')
+ kernbuf[count - 1] = 0;
+
for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
- if (memcmp(buffer, sync_on_cancel_states[i],
- strlen(sync_on_cancel_states[i])) == 0) {
+ if (strcmp(kernbuf, sync_on_cancel_states[i]) == 0) {
val = i;
break;
}
}
+
+ /* Legacy numeric codes */
if (val == -1) {
int rc;
+ /* Safe to use userspace buffer as lprocfs_write_helper will
+ * use copy from user for parsing */
rc = lprocfs_write_helper(buffer, count, &val);
if (rc)
return rc;
return rc;
}
-int lprocfs_ofd_wr_grant_compat_disable(struct file *file, const char *buffer,
+int lprocfs_ofd_wr_grant_compat_disable(struct file *file,
+ const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
&ofd->ofd_soft_sync_limit);
}
-int lprocfs_ofd_wr_soft_sync_limit(struct file *file, const char *buffer,
+int lprocfs_ofd_wr_soft_sync_limit(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
return lfsck_get_speed(ofd->ofd_osd, page, count);
}
-static int lprocfs_wr_lfsck_speed_limit(struct file *file, const char *buffer,
+static int lprocfs_wr_lfsck_speed_limit(struct file *file,
+ const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
ofd->ofd_inconsistency_self_repaired);
}
-static int lprocfs_wr_lfsck_verify_pfid(struct file *file, const char *buffer,
+static int lprocfs_wr_lfsck_verify_pfid(struct file *file,
+ const char __user *buffer,
unsigned long count, void *data)
{
struct obd_device *obd = data;
/* shrink the number of caching pages to a specific number */
static ssize_t
-osc_cached_mb_seq_write(struct file *file, const char *buffer,
+osc_cached_mb_seq_write(struct file *file, const char __user *buffer,
size_t count, loff_t *off)
{
struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
struct client_obd *cli = &dev->u.cli;
int pages_number, mult, rc;
+ char kernbuf[128];
+
+ if (count >= sizeof(kernbuf))
+ return -EINVAL;
+
+ if (copy_from_user(kernbuf, buffer, count))
+ return -EFAULT;
+ kernbuf[count] = 0;
mult = 1 << (20 - PAGE_CACHE_SHIFT);
- buffer = lprocfs_find_named_value(buffer, "used_mb:", &count);
+ buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
+ kernbuf;
rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
if (rc)
return rc;
return rc == 0 ? count : rc;
}
-static int lprocfs_osd_rd_iused_est(char *page, char **start, off_t off, int count,
- int *eof, void *data)
+static int lprocfs_osd_rd_iused_est(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
{
struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
LASSERT(osd != NULL);
return snprintf(page, count, "%d\n", osd->od_quota_iused_est);
}
-static int lprocfs_osd_wr_iused_est(struct file *file, const char *buffer,
- unsigned long count, void *data)
+static int lprocfs_osd_wr_iused_est(struct file *file,
+ const char __user *buffer,
+ unsigned long count, void *data)
{
struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
int rc, val;
noinst_PROGRAMS += openfilleddirunlink rename_many memhog
noinst_PROGRAMS += mmap_sanity writemany reads flocks_test flock_deadlock
noinst_PROGRAMS += write_time_limit rwv lgetxattr_size_check checkfiemap
-noinst_PROGRAMS += listxattr_size_check check_fhandle_syscalls
+noinst_PROGRAMS += listxattr_size_check check_fhandle_syscalls badarea_io
bin_PROGRAMS = mcreate munlink
testdir = $(libdir)/lustre/tests
--- /dev/null
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+int main(int argc, char **argv)
+{
+ int rc;
+ int fd = open(argv[1], O_WRONLY);
+
+ if (fd == -1) {
+ perror(argv[1]);
+ goto read;
+ }
+
+ /* We need rc because Sles11 compiler warns against unchecked
+ * return value of read and write */
+ rc = write(fd, (void *)0x4096000, 5);
+ if (rc != 5)
+ perror("write badarea (Should have failed)");
+
+ rc = write(fd, &fd, 0);
+ if (rc != 0)
+ perror("write zero bytes");
+
+ rc = write(fd, &fd, 1);
+ if (rc != 1)
+ perror("write one byte");
+
+ rc = write(fd, &fd, 2UL*1024*1024);
+ if (rc != 2UL*1024*1024)
+ perror("write 2M");
+
+ rc = write(fd, &fd, 2UL*1024*1024*1024);
+ if (rc != 2UL*1024*1024*1024)
+ perror("write 2G");
+
+ rc = write(fd, &fd, -2);
+ if (rc != -2)
+ perror("write -2");
+
+ close(fd);
+
+read:
+ fd = open(argv[1], O_RDONLY);
+ if (fd == -1)
+ return 0;
+ rc = read(fd, (void *)0x4096000, 5);
+ perror("read");
+
+ close(fd);
+
+ /* Tame the compiler spooked about rc assigned, but not used */
+ if (!rc)
+ return -1; /* Not really important. */
+
+ return 0;
+}
}
run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
+test_133g() {
+ local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
+ local facet
+
+ # Second verifying readability.
+ find $proc_dirs \
+ -type f \
+ -not -name force_lbug \
+ -not -name changelog_mask \
+ -exec badarea_io '{}' \; > /dev/null
+
+ [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
+ skip "Too old lustre on MDS"
+
+ [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
+ skip "Too old lustre on ost1"
+
+ for facet in $SINGLEMDS ost1; do
+ do_facet $facet find $proc_dirs \
+ -type f \
+ -not -name force_lbug \
+ -not -name changelog_mask \
+ -exec badarea_io '{}' \\\; &> /dev/null
+
+ done
+
+ true
+}
+run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
+
test_140() { #bug-17379
[ $PARALLEL == "yes" ] && skip "skip parallel run" && return
test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"