From patchwork Fri Nov 4 19:36:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Soheil Hassas Yeganeh X-Patchwork-Id: 691395 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3t9XF54zYKz9t9x for ; Sat, 5 Nov 2016 06:38:17 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VVgBN9WZ"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752979AbcKDThG (ORCPT ); Fri, 4 Nov 2016 15:37:06 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:33348 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752478AbcKDThF (ORCPT ); Fri, 4 Nov 2016 15:37:05 -0400 Received: by mail-qk0-f195.google.com with SMTP id x190so6589126qkb.0 for ; Fri, 04 Nov 2016 12:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=QAJOKmgSZ3wGOo/W7MEy8Y3D0yw2zHngPQdIJ+YrHWU=; b=VVgBN9WZuPjdYZOzaqOmG1FCWUGEibeOSBnadtTSTKKcqIkAEDm51AH+xP/7CmyTzI jyrInl/A9Bwb+1KPAM4eqr0nYQKJQ/wBLxE+zk5HV4PnOH/PMhS026t/iJozjH0nPRRr QoGa/ZmnHy5OgCboH3fh+/xle6490NdjhjpYhOn93v3M/AYB5aQr+4qsbeCRW5NLXGxU 06narLb1sFt7tVrl2tZhAR0Ea/S9ZvpuSSGJstsoLwe2BH2uubzSYioPC3IXH4GsjjWO 9JBmmY3sX3U9+5yCQcxsluKqTQhGPnqDT6Xe9ESzohmUYPsMtSAV9pc/JXEq0ORr106+ XCQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QAJOKmgSZ3wGOo/W7MEy8Y3D0yw2zHngPQdIJ+YrHWU=; b=Ek0ETSEB7tRkXdaVyZRCjuM1mkMwVMx7jfIhFHvUCTFeyQEKNd8mZ3X1gAy9Gqg6qk gGQ/g8ubTXs4tgFg0bJfjqyuq/ABGry22NACeM93uGIYIPx5JestFAaMAZbyWEJIIoqa S476uGMk2Ro4+XDpX9vV+9d8lytQkaV759L5XgWbgmye4L7/oYCk3B/7M8ToQiPgal8g f4zd3cMQc6GJ/nFLfer/sGAhaOTuHLsCc0n8e8san9jwKjTecckNbp1HRz9JeSkEKcFs YQEaPJWlq0zmshzAmavtkNMEcEzJZ8JiTFFGk0YiEoPp82iw/U4ff4EEEvkOjnv5ramM LXog== X-Gm-Message-State: ABUngvdsnO5ldOK5hwpQ4tJb4Sy1O8KK2/pZ70qGhWedSZGNdY2Gvts3wzEu63fIQgdUzQ== X-Received: by 10.233.239.204 with SMTP id d195mr14082853qkg.313.1478288224183; Fri, 04 Nov 2016 12:37:04 -0700 (PDT) Received: from soheil.nyc.corp.google.com ([100.101.230.57]) by smtp.gmail.com with ESMTPSA id a69sm1596261qkj.38.2016.11.04.12.37.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Nov 2016 12:37:03 -0700 (PDT) From: Soheil Hassas Yeganeh To: davem@davemloft.net, netdev@vger.kernel.org Cc: edumazet@google.com, willemb@google.com, ncardwell@google.com, Soheil Hassas Yeganeh Subject: [PATCH net] sock: fix sendmmsg for partial sendmsg Date: Fri, 4 Nov 2016 15:36:49 -0400 Message-Id: <1478288209-30893-1-git-send-email-soheil.kdev@gmail.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Soheil Hassas Yeganeh Do not send the next message in sendmmsg for partial sendmsg invocations. sendmmsg assumes that it can continue sending the next message when the return value of the individual sendmsg invocations is positive. It results in corrupting the data for TCP, SCTP, and UNIX streams. For example, sendmmsg([["abcd"], ["efgh"]]) can result in a stream of "aefgh" if the first sendmsg invocation sends only the first byte while the second sendmsg goes through. Datagram sockets either send the entire datagram or fail, so this patch affects only sockets of type SOCK_STREAM and SOCK_SEQPACKET. Fixes: 228e548e6020 ("net: Add sendmmsg socket system call") Signed-off-by: Soheil Hassas Yeganeh Signed-off-by: Eric Dumazet Signed-off-by: Willem de Bruijn Signed-off-by: Neal Cardwell Acked-by: Maciej Żenczykowski --- net/socket.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/socket.c b/net/socket.c index 5a9bf5e..272518b 100644 --- a/net/socket.c +++ b/net/socket.c @@ -2038,6 +2038,8 @@ int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, if (err) break; ++datagrams; + if (msg_data_left(&msg_sys)) + break; cond_resched(); }