Re: [PATCH 1/5] tty: n_gsm: Add raw-ip support

From: Alan Cox
Date: Mon Jun 06 2011 - 05:27:03 EST



> @@ -1590,6 +1616,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
> dlci->addr = addr;
> dlci->adaption = gsm->adaption;
> dlci->state = DLCI_CLOSED;
> + dlci->net = NULL; /* network not initially created */

kzalloc ised used anyway so this starts NULL

>
> +int gsm_change_mtu(struct net_device *net, int new_mtu)
> +{
> + if ((new_mtu < 8) || (new_mtu > MAX_MTU))
> + return -EINVAL;
> + net->mtu = new_mtu;
> + return 0;
> +}

Surely at that point you need to renegotiate the DLCI parameters for the
DLCI in question. At the very least you need to sanity check versus the
current settings ?


> +static int gsm_create_network(struct gsm_dlci *dlci, struct gsm_netconfig *nc)
> +{
> + char *netname;
> + int retval = 0;
> + struct net_device *net;
> + struct gsm_mux_net *mux_net;
> +
> + if (!capable(CAP_NET_ADMIN))
> + return -EPERM;
> +
> + /* Already in a non tty mode */
> + if (dlci->adaption > 2)
> + return -EBUSY;

Only you don't have any locking so two ioctls at once will get very
confused


> + if (retval) {
> + pr_err("network register fail %d\n", retval);
> + free_netdev(net);
> + goto error_ret;

And this leaves the DLCI messed up

> + kref_init(&mux_net->ref);

What stops this getting referenced between the net register and here ?

On the destroy side you don't seem to put back the old adaption settings
and restore the state (and also have locking v another ioctl missing)

Doesn't look too hard to fix - save the old dlci states when you go
network, put them back when you destroy the network state. For the ioctls
you probably need to cover most of each one with the mutex.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/