Skip to content

Commit 5b6c02d

Browse files
Al Viroarndb
authored andcommitted
compat_ioctl: move PPPIOCSCOMPRESS to ppp_generic
Rather than using a compat_alloc_user_space() buffer, moving this next to the native handler allows sharing most of the code, leaving only the user copy portion distinct. Signed-off-by: Al Viro <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Paul Mackerras <[email protected]> Cc: "David S. Miller" <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]>
1 parent 3e859ad commit 5b6c02d

File tree

2 files changed

+38
-47
lines changed

2 files changed

+38
-47
lines changed

drivers/net/ppp/ppp_generic.c

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ static void ppp_mp_insert(struct ppp *ppp, struct sk_buff *skb);
270270
static struct sk_buff *ppp_mp_reconstruct(struct ppp *ppp);
271271
static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb);
272272
#endif /* CONFIG_PPP_MULTILINK */
273-
static int ppp_set_compress(struct ppp *ppp, unsigned long arg);
273+
static int ppp_set_compress(struct ppp *ppp, struct ppp_option_data *data);
274274
static void ppp_ccp_peek(struct ppp *ppp, struct sk_buff *skb, int inbound);
275275
static void ppp_ccp_closed(struct ppp *ppp);
276276
static struct compressor *find_compressor(int type);
@@ -708,9 +708,14 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
708708
break;
709709

710710
case PPPIOCSCOMPRESS:
711-
err = ppp_set_compress(ppp, arg);
711+
{
712+
struct ppp_option_data data;
713+
if (copy_from_user(&data, argp, sizeof(data)))
714+
err = -EFAULT;
715+
else
716+
err = ppp_set_compress(ppp, &data);
712717
break;
713-
718+
}
714719
case PPPIOCGUNIT:
715720
if (put_user(ppp->file.index, p))
716721
break;
@@ -827,6 +832,13 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
827832
}
828833

829834
#ifdef CONFIG_COMPAT
835+
struct ppp_option_data32 {
836+
compat_uptr_t ptr;
837+
u32 length;
838+
compat_int_t transmit;
839+
};
840+
#define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
841+
830842
static long ppp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
831843
{
832844
struct ppp_file *pf;
@@ -863,6 +875,21 @@ static long ppp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long
863875
break;
864876
}
865877
#endif /* CONFIG_PPP_FILTER */
878+
case PPPIOCSCOMPRESS32:
879+
{
880+
struct ppp_option_data32 data32;
881+
if (copy_from_user(&data32, argp, sizeof(data32))) {
882+
err = -EFAULT;
883+
} else {
884+
struct ppp_option_data data = {
885+
.ptr = compat_ptr(data32.ptr),
886+
.length = data32.length,
887+
.transmit = data32.transmit
888+
};
889+
err = ppp_set_compress(ppp, &data);
890+
}
891+
break;
892+
}
866893
}
867894
}
868895
mutex_unlock(&ppp_mutex);
@@ -2783,24 +2810,20 @@ ppp_output_wakeup(struct ppp_channel *chan)
27832810

27842811
/* Process the PPPIOCSCOMPRESS ioctl. */
27852812
static int
2786-
ppp_set_compress(struct ppp *ppp, unsigned long arg)
2813+
ppp_set_compress(struct ppp *ppp, struct ppp_option_data *data)
27872814
{
2788-
int err;
2815+
int err = -EFAULT;
27892816
struct compressor *cp, *ocomp;
2790-
struct ppp_option_data data;
27912817
void *state, *ostate;
27922818
unsigned char ccp_option[CCP_MAX_OPTION_LENGTH];
27932819

2794-
err = -EFAULT;
2795-
if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
2796-
goto out;
2797-
if (data.length > CCP_MAX_OPTION_LENGTH)
2820+
if (data->length > CCP_MAX_OPTION_LENGTH)
27982821
goto out;
2799-
if (copy_from_user(ccp_option, (void __user *) data.ptr, data.length))
2822+
if (copy_from_user(ccp_option, data->ptr, data->length))
28002823
goto out;
28012824

28022825
err = -EINVAL;
2803-
if (data.length < 2 || ccp_option[1] < 2 || ccp_option[1] > data.length)
2826+
if (data->length < 2 || ccp_option[1] < 2 || ccp_option[1] > data->length)
28042827
goto out;
28052828

28062829
cp = try_then_request_module(
@@ -2810,8 +2833,8 @@ ppp_set_compress(struct ppp *ppp, unsigned long arg)
28102833
goto out;
28112834

28122835
err = -ENOBUFS;
2813-
if (data.transmit) {
2814-
state = cp->comp_alloc(ccp_option, data.length);
2836+
if (data->transmit) {
2837+
state = cp->comp_alloc(ccp_option, data->length);
28152838
if (state) {
28162839
ppp_xmit_lock(ppp);
28172840
ppp->xstate &= ~SC_COMP_RUN;
@@ -2829,7 +2852,7 @@ ppp_set_compress(struct ppp *ppp, unsigned long arg)
28292852
module_put(cp->owner);
28302853

28312854
} else {
2832-
state = cp->decomp_alloc(ccp_option, data.length);
2855+
state = cp->decomp_alloc(ccp_option, data->length);
28332856
if (state) {
28342857
ppp_recv_lock(ppp);
28352858
ppp->rstate &= ~SC_DECOMP_RUN;

fs/compat_ioctl.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@ static int sg_grt_trans(struct file *file,
9999
}
100100
#endif /* CONFIG_BLOCK */
101101

102-
struct ppp_option_data32 {
103-
compat_caddr_t ptr;
104-
u32 length;
105-
compat_int_t transmit;
106-
};
107-
#define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
108-
109102
struct ppp_idle32 {
110103
compat_time_t xmit_idle;
111104
compat_time_t recv_idle;
@@ -133,29 +126,6 @@ static int ppp_gidle(struct file *file, unsigned int cmd,
133126
return err;
134127
}
135128

136-
static int ppp_scompress(struct file *file, unsigned int cmd,
137-
struct ppp_option_data32 __user *odata32)
138-
{
139-
struct ppp_option_data __user *odata;
140-
__u32 data;
141-
void __user *datap;
142-
143-
odata = compat_alloc_user_space(sizeof(*odata));
144-
145-
if (get_user(data, &odata32->ptr))
146-
return -EFAULT;
147-
148-
datap = compat_ptr(data);
149-
if (put_user(datap, &odata->ptr))
150-
return -EFAULT;
151-
152-
if (copy_in_user(&odata->length, &odata32->length,
153-
sizeof(__u32) + sizeof(int)))
154-
return -EFAULT;
155-
156-
return do_ioctl(file, PPPIOCSCOMPRESS, (unsigned long) odata);
157-
}
158-
159129
/*
160130
* simple reversible transform to make our table more evenly
161131
* distributed after sorting.
@@ -249,8 +219,6 @@ static long do_ioctl_trans(unsigned int cmd,
249219
switch (cmd) {
250220
case PPPIOCGIDLE32:
251221
return ppp_gidle(file, cmd, argp);
252-
case PPPIOCSCOMPRESS32:
253-
return ppp_scompress(file, cmd, argp);
254222
#ifdef CONFIG_BLOCK
255223
case SG_GET_REQUEST_TABLE:
256224
return sg_grt_trans(file, cmd, argp);

0 commit comments

Comments
 (0)