From baddb36a93761de4b1c58ede7e43600389f7c9f0 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 11 Mar 2009 13:41:15 -0700 Subject: [PATCH] datapath: Always return EFAULT to userspace when copy_to/from_user() fails. copy_from_user() and copy_to_user() return the number of bytes that could not be copied, not a conventional error code, so we need to translate it into -EFAULT ourselves. --- datapath/datapath.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/datapath/datapath.c b/datapath/datapath.c index 851af969..e636c8ad 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -779,6 +779,7 @@ static int set_flow_actions(struct datapath *dp, struct odp_flow __user *ufp) error = -ENOMEM; if (!new_acts) goto error; + error = -EFAULT; if (copy_from_user(new_acts->actions, uf.actions, uf.n_actions * sizeof *uf.actions)) goto error_free_actions; @@ -1133,7 +1134,7 @@ get_dp_stats(struct datapath *dp, struct odp_stats __user *statsp) } stats.max_miss_queue = DP_MAX_QUEUE_LEN; stats.max_action_queue = DP_MAX_QUEUE_LEN; - return copy_to_user(statsp, &stats, sizeof stats); + return copy_to_user(statsp, &stats, sizeof stats) ? -EFAULT : 0; } static int @@ -1143,7 +1144,7 @@ put_port(const struct net_bridge_port *p, struct odp_port __user *uop) memset(&op, 0, sizeof op); strncpy(op.devname, p->dev->name, sizeof op.devname); op.port = p->port_no; - return copy_to_user(uop, &op, sizeof op); + return copy_to_user(uop, &op, sizeof op) ? -EFAULT : 0; } static int -- 2.30.2