From patchwork Thu Jul 26 14:59:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doron Roberts-Kedes X-Patchwork-Id: 949769 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=fb.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.b="SlRdBNrS"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41bwHm2LRyz9s0w for ; Fri, 27 Jul 2018 01:00:04 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731094AbeGZQRQ (ORCPT ); Thu, 26 Jul 2018 12:17:16 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:34554 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730083AbeGZQRQ (ORCPT ); Thu, 26 Jul 2018 12:17:16 -0400 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6QEsdDR022239 for ; Thu, 26 Jul 2018 08:00:02 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=Sf3ReiHgPrEVzenHENiSOSIUEoANdDtOy4eFdD+ZxMM=; b=SlRdBNrSXvWPElTB2WKKbebuohdSDInU3jFd0SLW1CftpT9sGp/L6RQ5T7FX8sAQb83x jyECHfKH2/msiPAjCzEKQuJeNZdnLQE3lHDVfLEcZM/6McTVLfS/w1OSalT0WPiZpsT6 PYE4O5BrjvYLc1O6ILjT9fNlbeOLVUMg8zs= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2kfg5082et-3 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 26 Jul 2018 08:00:02 -0700 Received: from mx-out.facebook.com (192.168.52.123) by mail.thefacebook.com (192.168.16.14) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 26 Jul 2018 08:00:01 -0700 Received: by devvm32402.prn1.facebook.com (Postfix, from userid 140145) id F025551B89C3; Thu, 26 Jul 2018 07:59:51 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Doron Roberts-Kedes Smtp-Origin-Hostname: devvm32402.prn1.facebook.com To: "David S . Miller" CC: Vakul Garg , Dave Watson , Matt Mullins , , Doron Roberts-Kedes Smtp-Origin-Cluster: prn1c35 Subject: [PATCH net-next v2 1/2] tls: Remove dead code in tls_sw_sendmsg Date: Thu, 26 Jul 2018 07:59:35 -0700 Message-ID: <20180726145936.3547913-2-doronrk@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180726145936.3547913-1-doronrk@fb.com> References: <20180726145936.3547913-1-doronrk@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-26_04:, , signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org tls_push_record either returns 0 on success or a negative value on failure. This patch removes code that would only be executed if tls_push_record were to return a positive value. Signed-off-by: Doron Roberts-Kedes --- net/tls/tls_sw.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 03f1370f5db1..0279bc4a168b 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -423,12 +423,10 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) copied += try_to_copy; ret = tls_push_record(sk, msg->msg_flags, record_type); - if (!ret) - continue; - if (ret < 0) + if (ret) goto send_end; + continue; - copied -= try_to_copy; fallback_to_reg_send: iov_iter_revert(&msg->msg_iter, ctx->sg_plaintext_size - orig_size); From patchwork Thu Jul 26 14:59:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doron Roberts-Kedes X-Patchwork-Id: 949767 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=fb.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.b="XdCtVgPM"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41bwHj6fMGz9ryn for ; Fri, 27 Jul 2018 01:00:01 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731610AbeGZQRO (ORCPT ); Thu, 26 Jul 2018 12:17:14 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:34532 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730517AbeGZQRO (ORCPT ); Thu, 26 Jul 2018 12:17:14 -0400 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6QEsb8O022232 for ; Thu, 26 Jul 2018 07:59:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=l3BFDqQc6JkwtkswMGo5Z2Eoe5EYGIVYaZB1nGk820g=; b=XdCtVgPMoc1Y/HViU6p+sQk0u9StuxLb1B83ikglgOrPzHGrWNf5O+GZQ6HFFoCOB7XQ q+rp3Z8mNzEdFM3rgxp1c1WnXVpbL5RtLxcyE+F8HWBdeRTd7Fsf86POwYLwxYNREOi4 /z020ule8c6fhmrD3TcFtl1+jptWi983vH0= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2kfg5082em-3 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 26 Jul 2018 07:59:59 -0700 Received: from mx-out.facebook.com (192.168.52.123) by mail.thefacebook.com (192.168.16.17) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 26 Jul 2018 07:59:58 -0700 Received: by devvm32402.prn1.facebook.com (Postfix, from userid 140145) id E7E8651B89C6; Thu, 26 Jul 2018 07:59:52 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Doron Roberts-Kedes Smtp-Origin-Hostname: devvm32402.prn1.facebook.com To: "David S . Miller" CC: Vakul Garg , Dave Watson , Matt Mullins , , Doron Roberts-Kedes Smtp-Origin-Cluster: prn1c35 Subject: [PATCH net-next v2 2/2] tls: Fix improper revert in zerocopy_from_iter Date: Thu, 26 Jul 2018 07:59:36 -0700 Message-ID: <20180726145936.3547913-3-doronrk@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180726145936.3547913-1-doronrk@fb.com> References: <20180726145936.3547913-1-doronrk@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-26_04:, , signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The current code is problematic because the iov_iter is reverted and never advanced in the non-error case. This patch skips the revert in the non-error case. This patch also fixes the amount by which the iov_iter is reverted. Currently, iov_iter is reverted by size, which can be greater than the amount by which the iter was actually advanced. Instead, only revert by the amount that the iter was advanced. Fixes: 4718799817c5 ("tls: Fix zerocopy_from_iter iov handling") Signed-off-by: Doron Roberts-Kedes --- net/tls/tls_sw.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 0279bc4a168b..190b0aa79c85 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -263,7 +263,7 @@ static int zerocopy_from_iter(struct sock *sk, struct iov_iter *from, int length, int *pages_used, unsigned int *size_used, struct scatterlist *to, int to_max_pages, - bool charge, bool revert) + bool charge) { struct page *pages[MAX_SKB_FRAGS]; @@ -312,10 +312,10 @@ static int zerocopy_from_iter(struct sock *sk, struct iov_iter *from, } out: + if (rc) + iov_iter_revert(from, size - *size_used); *size_used = size; *pages_used = num_elem; - if (revert) - iov_iter_revert(from, size); return rc; } @@ -417,7 +417,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) &ctx->sg_plaintext_size, ctx->sg_plaintext_data, ARRAY_SIZE(ctx->sg_plaintext_data), - true, false); + true); if (ret) goto fallback_to_reg_send; @@ -428,8 +428,6 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) continue; fallback_to_reg_send: - iov_iter_revert(&msg->msg_iter, - ctx->sg_plaintext_size - orig_size); trim_sg(sk, ctx->sg_plaintext_data, &ctx->sg_plaintext_num_elem, &ctx->sg_plaintext_size, @@ -833,7 +831,7 @@ int tls_sw_recvmsg(struct sock *sk, err = zerocopy_from_iter(sk, &msg->msg_iter, to_copy, &pages, &chunk, &sgin[1], - MAX_SKB_FRAGS, false, true); + MAX_SKB_FRAGS, false); if (err < 0) goto fallback_to_reg_recv;