Commit ec98ea70 authored by Chris Leech's avatar Chris Leech Committed by Martin K. Petersen

scsi: iscsi: Ensure sysfs attributes are limited to PAGE_SIZE

As the iSCSI parameters are exported back through sysfs, it should be
enforcing that they never are more than PAGE_SIZE (which should be more
than enough) before accepting updates through netlink.

Change all iSCSI sysfs attributes to use sysfs_emit().

Cc: stable@vger.kernel.org
Reported-by: default avatarAdam Nichols <adam@grimm-co.com>
Reviewed-by: default avatarLee Duncan <lduncan@suse.com>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: default avatarMike Christie <michael.christie@oracle.com>
Signed-off-by: default avatarChris Leech <cleech@redhat.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 688e8128
This diff is collapsed.
...@@ -135,7 +135,8 @@ show_transport_handle(struct device *dev, struct device_attribute *attr, ...@@ -135,7 +135,8 @@ show_transport_handle(struct device *dev, struct device_attribute *attr,
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EACCES; return -EACCES;
return sprintf(buf, "%llu\n", (unsigned long long)iscsi_handle(priv->iscsi_transport)); return sysfs_emit(buf, "%llu\n",
(unsigned long long)iscsi_handle(priv->iscsi_transport));
} }
static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL); static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL);
...@@ -145,7 +146,7 @@ show_transport_##name(struct device *dev, \ ...@@ -145,7 +146,7 @@ show_transport_##name(struct device *dev, \
struct device_attribute *attr,char *buf) \ struct device_attribute *attr,char *buf) \
{ \ { \
struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \ struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \
return sprintf(buf, format"\n", priv->iscsi_transport->name); \ return sysfs_emit(buf, format"\n", priv->iscsi_transport->name);\
} \ } \
static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL); static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
...@@ -186,7 +187,7 @@ static ssize_t ...@@ -186,7 +187,7 @@ static ssize_t
show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf) show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf)
{ {
struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev); struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
return sprintf(buf, "%llu\n", (unsigned long long) ep->id); return sysfs_emit(buf, "%llu\n", (unsigned long long) ep->id);
} }
static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL); static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL);
...@@ -2883,6 +2884,9 @@ iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev) ...@@ -2883,6 +2884,9 @@ iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
struct iscsi_cls_session *session; struct iscsi_cls_session *session;
int err = 0, value = 0; int err = 0, value = 0;
if (ev->u.set_param.len > PAGE_SIZE)
return -EINVAL;
session = iscsi_session_lookup(ev->u.set_param.sid); session = iscsi_session_lookup(ev->u.set_param.sid);
conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid); conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
if (!conn || !session) if (!conn || !session)
...@@ -3030,6 +3034,9 @@ iscsi_set_host_param(struct iscsi_transport *transport, ...@@ -3030,6 +3034,9 @@ iscsi_set_host_param(struct iscsi_transport *transport,
if (!transport->set_host_param) if (!transport->set_host_param)
return -ENOSYS; return -ENOSYS;
if (ev->u.set_host_param.len > PAGE_SIZE)
return -EINVAL;
shost = scsi_host_lookup(ev->u.set_host_param.host_no); shost = scsi_host_lookup(ev->u.set_host_param.host_no);
if (!shost) { if (!shost) {
printk(KERN_ERR "set_host_param could not find host no %u\n", printk(KERN_ERR "set_host_param could not find host no %u\n",
...@@ -3963,7 +3970,7 @@ static ssize_t show_conn_state(struct device *dev, ...@@ -3963,7 +3970,7 @@ static ssize_t show_conn_state(struct device *dev,
conn->state < ARRAY_SIZE(connection_state_names)) conn->state < ARRAY_SIZE(connection_state_names))
state = connection_state_names[conn->state]; state = connection_state_names[conn->state];
return sprintf(buf, "%s\n", state); return sysfs_emit(buf, "%s\n", state);
} }
static ISCSI_CLASS_ATTR(conn, state, S_IRUGO, show_conn_state, static ISCSI_CLASS_ATTR(conn, state, S_IRUGO, show_conn_state,
NULL); NULL);
...@@ -4191,7 +4198,7 @@ show_priv_session_state(struct device *dev, struct device_attribute *attr, ...@@ -4191,7 +4198,7 @@ show_priv_session_state(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent); struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
return sprintf(buf, "%s\n", iscsi_session_state_name(session->state)); return sysfs_emit(buf, "%s\n", iscsi_session_state_name(session->state));
} }
static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state, static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
NULL); NULL);
...@@ -4200,7 +4207,7 @@ show_priv_session_creator(struct device *dev, struct device_attribute *attr, ...@@ -4200,7 +4207,7 @@ show_priv_session_creator(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent); struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
return sprintf(buf, "%d\n", session->creator); return sysfs_emit(buf, "%d\n", session->creator);
} }
static ISCSI_CLASS_ATTR(priv_sess, creator, S_IRUGO, show_priv_session_creator, static ISCSI_CLASS_ATTR(priv_sess, creator, S_IRUGO, show_priv_session_creator,
NULL); NULL);
...@@ -4209,7 +4216,7 @@ show_priv_session_target_id(struct device *dev, struct device_attribute *attr, ...@@ -4209,7 +4216,7 @@ show_priv_session_target_id(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent); struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
return sprintf(buf, "%d\n", session->target_id); return sysfs_emit(buf, "%d\n", session->target_id);
} }
static ISCSI_CLASS_ATTR(priv_sess, target_id, S_IRUGO, static ISCSI_CLASS_ATTR(priv_sess, target_id, S_IRUGO,
show_priv_session_target_id, NULL); show_priv_session_target_id, NULL);
...@@ -4222,8 +4229,8 @@ show_priv_session_##field(struct device *dev, \ ...@@ -4222,8 +4229,8 @@ show_priv_session_##field(struct device *dev, \
struct iscsi_cls_session *session = \ struct iscsi_cls_session *session = \
iscsi_dev_to_session(dev->parent); \ iscsi_dev_to_session(dev->parent); \
if (session->field == -1) \ if (session->field == -1) \
return sprintf(buf, "off\n"); \ return sysfs_emit(buf, "off\n"); \
return sprintf(buf, format"\n", session->field); \ return sysfs_emit(buf, format"\n", session->field); \
} }
#define iscsi_priv_session_attr_store(field) \ #define iscsi_priv_session_attr_store(field) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment