From: Steffen Klassert Subject: Re: [PATCH ipsec-next] xfrm: policy: fix policy hash rebuild Date: Fri, 30 Nov 2018 12:47:32 +0100 Message-ID: <20181130114732.GX8742@gauss3.secunet.de> References: <20181127122854.13538-1-fw@strlen.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Cc: , To: Florian Westphal Return-path: Received: from a.mx.secunet.com ([62.96.220.36]:46394 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726473AbeK3W4f (ORCPT ); Fri, 30 Nov 2018 17:56:35 -0500 Content-Disposition: inline In-Reply-To: <20181127122854.13538-1-fw@strlen.de> Sender: netdev-owner@vger.kernel.org List-ID: On Tue, Nov 27, 2018 at 01:28:54PM +0100, Florian Westphal wrote: > Dan Carpenter reports following static checker warning: > net/xfrm/xfrm_policy.c:1316 xfrm_hash_rebuild() > warn: 'dir' is out of bounds '3' vs '2' > > | 1280 /* reset the bydst and inexact table in all directions */ > | 1281 xfrm_hash_reset_inexact_table(net); > | 1282 > | 1283 for (dir = 0; dir < XFRM_POLICY_MAX; dir++) { > | ^^^^^^^^^^^^^^^^^^^^^ > |dir == XFRM_POLICY_MAX at the end of this loop. > | 1304 /* re-insert all policies by order of creation */ > | 1305 list_for_each_entry_reverse(policy, &net->xfrm.policy_all, walk.all) { > [..] > | 1314 xfrm_policy_id2dir(policy->index)); > | 1315 if (!chain) { > | 1316 void *p = xfrm_policy_inexact_insert(policy, dir, 0); > > Fix this by updating 'dir' based on current policy. Otherwise, the > inexact policies won't be found anymore during lookup, as they get > hashed to a bogus bin. > > Reported-by: Dan Carpenter > Fixes: cc1bb845adc9 ("xfrm: policy: return NULL when inexact search needed") > Signed-off-by: Florian Westphal Applied, thanks Florian!