1  /* { dg-do compile } */
       2  // TODO: remove need for -fanalyzer-checker=taint here:
       3  /* { dg-options "-fanalyzer -fanalyzer-checker=taint" } */
       4  /* { dg-require-effective-target analyzer } */
       5  
       6  /* See notes in this header.  */
       7  #include "taint-CVE-2011-0521.h"
       8  
       9  // TODO: remove need for this option
      10  /* { dg-additional-options "-fanalyzer-checker=taint" } */
      11  
      12  /* Adapted from drivers/media/dvb/ttpci/av7110_ca.c  */
      13  
      14  int dvb_ca_ioctl(struct file *file, unsigned int cmd, void *parg)
      15  {
      16  	struct dvb_device *dvbdev = file->private_data;
      17  	struct av7110 *av7110 = dvbdev->priv;
      18  	unsigned long arg = (unsigned long) parg;
      19  
      20  	/* case CA_GET_SLOT_INFO:  */
      21  	{
      22  		ca_slot_info_t *info=(ca_slot_info_t *)parg;
      23  
      24  		if (info->num < 0 || info->num > 1)
      25  			return -EINVAL;
      26  		av7110->ci_slot[info->num].num = info->num; /* { dg-bogus "attacker-controlled value" } */
      27  		av7110->ci_slot[info->num].type = FW_CI_LL_SUPPORT(av7110->arm_app) ?
      28  							CA_CI_LINK : CA_CI;
      29  		memcpy(info, &av7110->ci_slot[info->num], sizeof(ca_slot_info_t));
      30  	}
      31  	return 0;
      32  }
      33  
      34  /* Adapted from drivers/media/dvb/dvb-core/dvbdev.c
      35     Further simplified from -2; always use an on-stack buffer.  */
      36  
      37  static DEFINE_MUTEX(dvbdev_mutex);
      38  
      39  int dvb_usercopy(struct file *file,
      40  		 unsigned int cmd, unsigned long arg)
      41  {
      42  	char    sbuf[128];
      43  	void    *parg = sbuf;
      44  	int     err = -EFAULT;
      45  	if (copy_from_user(parg, (void __user *)arg, sizeof(sbuf)))
      46  	  goto out;
      47  
      48  	mutex_lock(&dvbdev_mutex);
      49  	if ((err = dvb_ca_ioctl(file, cmd, parg)) == -ENOIOCTLCMD)
      50  		err = -EINVAL;
      51  	mutex_unlock(&dvbdev_mutex);
      52  
      53  	if (err < 0)
      54  		goto out;
      55  
      56  	if (copy_to_user((void __user *)arg, parg, sizeof(sbuf)))
      57  	  err = -EFAULT;
      58  
      59  out:
      60  	return err;
      61  }