Bug 47111 - shutdown(2) does not correctly handle invalid how
Summary: shutdown(2) does not correctly handle invalid how
Status: RESOLVED CODE_FIX
Alias: None
Product: Networking
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Stephen Hemminger
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-06 09:35 UTC by Michael Kerrisk
Modified: 2012-10-30 16:07 UTC (History)
0 users

See Also:
Kernel Version:
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Michael Kerrisk 2012-09-06 09:35:43 UTC
The POSIX specification of shutdown says:

  how  Specifies  the  type of shutdown. The values are as fol‐
              lows:

       SHUT_RD
              Disables further receive operations.

       SHUT_WR
              Disables further send operations.

       SHUT_RDWR
              Disables further send and receive operations.
   ...

   ERRORS
       The shutdown() function shall fail if:

       EINVAL The how argument is invalid.

However, Linux inconsistently handles this error scenario, via protocol-specific checks. In particular, the various INET domains correctly give EINVAL for invalid 'how', but UNIX domain sockets simply ignore invalid values.

There should be a check in the top-level syscall code to handle this case. The attached patch adds that check. 

Note: this patch brings POSIX conformance, and brings consistency to the API, but changes the ABI for oddball applications that happen to specify strange values in 'how' for previously unchecked domain (e.g., UNIX domain).
Comment 1 Michael Kerrisk 2012-09-06 14:39:59 UTC
So, Eric Dumazet points out to me that there are patches in net-next to fix this for AD_UNIX and AF_DECNet. Perhaps this bug is soon closeable.
Comment 2 Stephen Hemminger 2012-10-30 16:07:55 UTC
Fixed in 3.7-rc1

Note You need to log in before you can comment on or make changes to this bug.