Bug 47111

Summary: shutdown(2) does not correctly handle invalid how
Product: Networking Reporter: Michael Kerrisk (mtk.manpages)
Component: OtherAssignee: Stephen Hemminger (stephen)
Status: RESOLVED CODE_FIX    
Severity: normal    
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: Subsystem:
Regression: No Bisected commit-id:

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