Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2967730imm; Sun, 1 Jul 2018 09:21:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLgOQgO64iZ5O5YEzzEcH5T1QLkpRvROm/2efr4DPJMkgmf/9tIo+cmwZ7bo8m4pVmgiU8n X-Received: by 2002:a63:7558:: with SMTP id f24-v6mr19379694pgn.314.1530462061726; Sun, 01 Jul 2018 09:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530462061; cv=none; d=google.com; s=arc-20160816; b=CxkFZM6KUQay46EOoPzu90VMKflyGZ3Zx3mrFCXYh9NGBw68+cVQeQYXmmedx4PdzB WlSgRXfYYJmvtR3i99vxh16qSmlEtOsCTjfuD4UoFaBmRouT8+s+tz4Cl2OEUKQmjVx7 328/zswlT57qkRmbgENf79YozO9SKjg/lsVgpb3CfCDuatHcehVm/p3r+3ITn0dUMpOE K2ce6I24TMmLz9MfevEZQ3I5dwEp+yfGQMfjV0wBoVQEgQDwaMgCh6j+tkiWj33Ow5DJ 0/F7hRwiLm+5f9ohm901Kvx2AP06oCW9eoKj6yt427L4o8Qquh0aofa9UlED1JyWm+/s /XpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ibJ6+mIU6sD6BAvAbNtSSVZmYlte1z09DscrpEaE+rg=; b=GphsGA2ExNmq2ce3s/y03eqpoEI+sp2Bh2jsgTbG1O9bizOGck8ef/OPX305YqmTi/ hROUuhlYSWAHl5yd6hM6MI5vrhWRBwuPNk/y/cPiO942aqqVvm3G0+GNqG3tye8dZYAm zw+ZIxMMAD4cXvVjLSKX49ajojrrSa/j963+yWODOWouqrTXyHYu/v6ldc8MCYeiqkPU JEIygnz3Uz7FY8bnpFvaVjBil20DPCno1UxrrD16onn7BlFyxebNwGoezmmm0+ozq7Bp Ia1pQ9V5mmcdZ6Cw4qcLrc7uBISoVEkicFL0grtxuY87mvpkg2SlsboRexpAqAKlyY4o JjUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s3-v6si14417611plb.394.2018.07.01.09.20.47; Sun, 01 Jul 2018 09:21:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753498AbeGAQTO (ORCPT + 99 others); Sun, 1 Jul 2018 12:19:14 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33152 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753217AbeGAQTK (ORCPT ); Sun, 1 Jul 2018 12:19:10 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0636049B; Sun, 1 Jul 2018 16:19:09 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tobias Brunner , Herbert Xu , Steffen Klassert , Zubin Mithra Subject: [PATCH 4.4 075/105] xfrm: Ignore socket policies when rebuilding hash tables Date: Sun, 1 Jul 2018 18:02:25 +0200 Message-Id: <20180701153154.850207079@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701153149.382300170@linuxfoundation.org> References: <20180701153149.382300170@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tobias Brunner commit 6916fb3b10b3cbe3b1f9f5b680675f53e4e299eb upstream. Whenever thresholds are changed the hash tables are rebuilt. This is done by enumerating all policies and hashing and inserting them into the right table according to the thresholds and direction. Because socket policies are also contained in net->xfrm.policy_all but no hash tables are defined for their direction (dir + XFRM_POLICY_MAX) this causes a NULL or invalid pointer dereference after returning from policy_hash_bysel() if the rebuild is done while any socket policies are installed. Since the rebuild after changing thresholds is scheduled this crash could even occur if the userland sets thresholds seemingly before installing any socket policies. Fixes: 53c2e285f970 ("xfrm: Do not hash socket policies") Signed-off-by: Tobias Brunner Acked-by: Herbert Xu Signed-off-by: Steffen Klassert Cc: Zubin Mithra Signed-off-by: Greg Kroah-Hartman --- net/xfrm/xfrm_policy.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -626,6 +626,10 @@ static void xfrm_hash_rebuild(struct wor /* re-insert all policies by order of creation */ list_for_each_entry_reverse(policy, &net->xfrm.policy_all, walk.all) { + if (xfrm_policy_id2dir(policy->index) >= XFRM_POLICY_MAX) { + /* skip socket policies */ + continue; + } newpos = NULL; chain = policy_hash_bysel(net, &policy->selector, policy->family,