Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751784Ab2H0CrX (ORCPT ); Sun, 26 Aug 2012 22:47:23 -0400 Received: from mail-vc0-f174.google.com ([209.85.220.174]:60577 "EHLO mail-vc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751010Ab2H0CrV (ORCPT ); Sun, 26 Aug 2012 22:47:21 -0400 From: Xi Wang To: "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Xi Wang Subject: [PATCH] af_unix: fix shutdown parameter checking Date: Sun, 26 Aug 2012 22:47:13 -0400 Message-Id: <1346035633-2492-1-git-send-email-xi.wang@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1284 Lines: 47 Return -EINVAL rather than 0 given an invalid "mode" parameter. Signed-off-by: Xi Wang --- Another way to check "mode" is as in inet_shutdown(): mode++; if ((mode & ~SHUTDOWN_MASK) || !mode) return -EINVAL; This patch uses a simpler form, to check if "mode" is in the range SHUT_RD ... SHUT_RDWR. --- net/unix/af_unix.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index c5ee4ff..8a84ab6 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2060,10 +2060,14 @@ static int unix_shutdown(struct socket *sock, int mode) struct sock *sk = sock->sk; struct sock *other; - mode = (mode+1)&(RCV_SHUTDOWN|SEND_SHUTDOWN); - - if (!mode) - return 0; + if (mode < SHUT_RD || mode > SHUT_RDWR) + return -EINVAL; + /* This maps: + * SHUT_RD (0) -> RCV_SHUTDOWN (1) + * SHUT_WR (1) -> SEND_SHUTDOWN (2) + * SHUT_RDWR (2) -> SHUTDOWN_MASK (3) + */ + ++mode; unix_state_lock(sk); sk->sk_shutdown |= mode; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/