Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-spi' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull spi uaccess delousing from Al Viro:
"Getting rid of pointless __get_user() and friends in drivers/spi.

[ the only reason it's on a separate branch is that I hoped it would
be picked by spi folks; looks like mail asking them to grab it got
lost and I hadn't followed up on that ]"

* 'for-spi' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
spidev: quit messing with access_ok()

+11 -31
+11 -31
drivers/spi/spidev.c
··· 253 253 goto done; 254 254 } 255 255 k_tmp->rx_buf = rx_buf; 256 - if (!access_ok(VERIFY_WRITE, (u8 __user *) 257 - (uintptr_t) u_tmp->rx_buf, 258 - u_tmp->len)) 259 - goto done; 260 256 rx_buf += k_tmp->len; 261 257 } 262 258 if (u_tmp->tx_buf) { ··· 300 304 rx_buf = spidev->rx_buffer; 301 305 for (n = n_xfers, u_tmp = u_xfers; n; n--, u_tmp++) { 302 306 if (u_tmp->rx_buf) { 303 - if (__copy_to_user((u8 __user *) 307 + if (copy_to_user((u8 __user *) 304 308 (uintptr_t) u_tmp->rx_buf, rx_buf, 305 309 u_tmp->len)) { 306 310 status = -EFAULT; ··· 342 346 static long 343 347 spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 344 348 { 345 - int err = 0; 346 349 int retval = 0; 347 350 struct spidev_data *spidev; 348 351 struct spi_device *spi; ··· 352 357 /* Check type and command number */ 353 358 if (_IOC_TYPE(cmd) != SPI_IOC_MAGIC) 354 359 return -ENOTTY; 355 - 356 - /* Check access direction once here; don't repeat below. 357 - * IOC_DIR is from the user perspective, while access_ok is 358 - * from the kernel perspective; so they look reversed. 359 - */ 360 - if (_IOC_DIR(cmd) & _IOC_READ) 361 - err = !access_ok(VERIFY_WRITE, 362 - (void __user *)arg, _IOC_SIZE(cmd)); 363 - if (err == 0 && _IOC_DIR(cmd) & _IOC_WRITE) 364 - err = !access_ok(VERIFY_READ, 365 - (void __user *)arg, _IOC_SIZE(cmd)); 366 - if (err) 367 - return -EFAULT; 368 360 369 361 /* guard against device removal before, or while, 370 362 * we issue this ioctl. ··· 375 393 switch (cmd) { 376 394 /* read requests */ 377 395 case SPI_IOC_RD_MODE: 378 - retval = __put_user(spi->mode & SPI_MODE_MASK, 396 + retval = put_user(spi->mode & SPI_MODE_MASK, 379 397 (__u8 __user *)arg); 380 398 break; 381 399 case SPI_IOC_RD_MODE32: 382 - retval = __put_user(spi->mode & SPI_MODE_MASK, 400 + retval = put_user(spi->mode & SPI_MODE_MASK, 383 401 (__u32 __user *)arg); 384 402 break; 385 403 case SPI_IOC_RD_LSB_FIRST: 386 - retval = __put_user((spi->mode & SPI_LSB_FIRST) ? 1 : 0, 404 + retval = put_user((spi->mode & SPI_LSB_FIRST) ? 1 : 0, 387 405 (__u8 __user *)arg); 388 406 break; 389 407 case SPI_IOC_RD_BITS_PER_WORD: 390 - retval = __put_user(spi->bits_per_word, (__u8 __user *)arg); 408 + retval = put_user(spi->bits_per_word, (__u8 __user *)arg); 391 409 break; 392 410 case SPI_IOC_RD_MAX_SPEED_HZ: 393 - retval = __put_user(spidev->speed_hz, (__u32 __user *)arg); 411 + retval = put_user(spidev->speed_hz, (__u32 __user *)arg); 394 412 break; 395 413 396 414 /* write requests */ 397 415 case SPI_IOC_WR_MODE: 398 416 case SPI_IOC_WR_MODE32: 399 417 if (cmd == SPI_IOC_WR_MODE) 400 - retval = __get_user(tmp, (u8 __user *)arg); 418 + retval = get_user(tmp, (u8 __user *)arg); 401 419 else 402 - retval = __get_user(tmp, (u32 __user *)arg); 420 + retval = get_user(tmp, (u32 __user *)arg); 403 421 if (retval == 0) { 404 422 u32 save = spi->mode; 405 423 ··· 418 436 } 419 437 break; 420 438 case SPI_IOC_WR_LSB_FIRST: 421 - retval = __get_user(tmp, (__u8 __user *)arg); 439 + retval = get_user(tmp, (__u8 __user *)arg); 422 440 if (retval == 0) { 423 441 u32 save = spi->mode; 424 442 ··· 435 453 } 436 454 break; 437 455 case SPI_IOC_WR_BITS_PER_WORD: 438 - retval = __get_user(tmp, (__u8 __user *)arg); 456 + retval = get_user(tmp, (__u8 __user *)arg); 439 457 if (retval == 0) { 440 458 u8 save = spi->bits_per_word; 441 459 ··· 448 466 } 449 467 break; 450 468 case SPI_IOC_WR_MAX_SPEED_HZ: 451 - retval = __get_user(tmp, (__u32 __user *)arg); 469 + retval = get_user(tmp, (__u32 __user *)arg); 452 470 if (retval == 0) { 453 471 u32 save = spi->max_speed_hz; 454 472 ··· 498 516 struct spi_ioc_transfer *ioc; 499 517 500 518 u_ioc = (struct spi_ioc_transfer __user *) compat_ptr(arg); 501 - if (!access_ok(VERIFY_READ, u_ioc, _IOC_SIZE(cmd))) 502 - return -EFAULT; 503 519 504 520 /* guard against device removal before, or while, 505 521 * we issue this ioctl.