Commit b9c54f91a48146778fe91423d4d467a0ee8c719b

Authored by Andy Walker
Committed by David S. Miller
1 parent b9b64e6e89

[SPARC]: Fix regression in sys_getdomainname()

This patch corrects the buffer length checking in the
sys_getdomainname() implementation for sparc/sparc64.

Signed-off-by: Andy Walker <andy@puszczka.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 2 changed files with 12 additions and 8 deletions Side-by-side Diff

arch/sparc/kernel/sys_sparc.c
... ... @@ -470,19 +470,21 @@
470 470 {
471 471 int nlen, err;
472 472  
473   - if (len < 0 || len > __NEW_UTS_LEN)
  473 + if (len < 0)
474 474 return -EINVAL;
475 475  
476 476 down_read(&uts_sem);
477 477  
478 478 nlen = strlen(system_utsname.domainname) + 1;
479   - if (nlen < len)
480   - len = nlen;
  479 + err = -EINVAL;
  480 + if (nlen > len)
  481 + goto out;
481 482  
482 483 err = -EFAULT;
483   - if (!copy_to_user(name, system_utsname.domainname, len))
  484 + if (!copy_to_user(name, system_utsname.domainname, nlen))
484 485 err = 0;
485 486  
  487 +out:
486 488 up_read(&uts_sem);
487 489 return err;
488 490 }
arch/sparc64/kernel/sys_sparc.c
... ... @@ -707,19 +707,21 @@
707 707 {
708 708 int nlen, err;
709 709  
710   - if (len < 0 || len > __NEW_UTS_LEN)
  710 + if (len < 0)
711 711 return -EINVAL;
712 712  
713 713 down_read(&uts_sem);
714 714  
715 715 nlen = strlen(system_utsname.domainname) + 1;
716   - if (nlen < len)
717   - len = nlen;
  716 + err = -EINVAL;
  717 + if (nlen > len)
  718 + goto out;
718 719  
719 720 err = -EFAULT;
720   - if (!copy_to_user(name, system_utsname.domainname, len))
  721 + if (!copy_to_user(name, system_utsname.domainname, nlen))
721 722 err = 0;
722 723  
  724 +out:
723 725 up_read(&uts_sem);
724 726 return err;
725 727 }