From patchwork Tue Jan 16 09:00:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Lesokhin X-Patchwork-Id: 861343 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@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=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zLPMN6KB6z9s83 for ; Tue, 16 Jan 2018 20:00:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750832AbeAPJAp (ORCPT ); Tue, 16 Jan 2018 04:00:45 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48434 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750716AbeAPJAo (ORCPT ); Tue, 16 Jan 2018 04:00:44 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from ilyal@mellanox.com) with ESMTPS (AES256-SHA encrypted); 16 Jan 2018 11:00:40 +0200 Received: from gen-l-vrt-094.mtl.labs.mlnx (gen-l-vrt-094.mtl.labs.mlnx [10.137.9.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w0G90ekV026624; Tue, 16 Jan 2018 11:00:40 +0200 From: Ilya Lesokhin To: netdev@vger.kernel.org, davem@davemloft.net Cc: davejwatson@fb.com, Ilya Lesokhin Subject: [PATCH net 1/1] net/tls: Only attach to sockets in ESTABLISHED state Date: Tue, 16 Jan 2018 11:00:37 +0200 Message-Id: <20180116090037.44423-1-ilyal@mellanox.com> X-Mailer: git-send-email 2.15.0.317.g14c63a9 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Calling accept on a TCP socket with a TLS ulp attached results in two sockets that share the same ulp context. The ulp context is freed while a socket is destroyed, so after one of the sockets is released, the second second will trigger a use after free when it tries to access the ulp context attached to it. We restrict the TLS ulp to sockets in ESTABLISHED state to prevent the scenario above. Fixes: 3c4d755 ('tls: kernel TLS support') Reported-by: syzbot+904e7cd6c5c741609228@syzkaller.appspotmail.com Signed-off-by: Ilya Lesokhin --- net/tls/tls_main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index e07ee3ae0023..a1a4e50acb53 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -454,6 +454,15 @@ static int tls_init(struct sock *sk) struct tls_context *ctx; int rc = 0; + /* The TLS ulp is correnctly supported only for TCP sockets + * in ESTABLISHED state. + * Supporting sockets in TCP_LISTEN state will require us + * to modify the accept implementation to clone rather then + * share the ulp context. + */ + if (sk->sk_state != TCP_ESTABLISHED) + return -ENOTSUPP; + /* allocate tls context */ ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) {