From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4888BC433DB for ; Tue, 29 Dec 2020 16:03:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D17120825 for ; Tue, 29 Dec 2020 16:03:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726690AbgL2QDI (ORCPT ); Tue, 29 Dec 2020 11:03:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgL2QDH (ORCPT ); Tue, 29 Dec 2020 11:03:07 -0500 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93F4DC06179F for ; Tue, 29 Dec 2020 08:01:46 -0800 (PST) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1kuHR9-00012o-0y; Tue, 29 Dec 2020 17:01:27 +0100 Date: Tue, 29 Dec 2020 17:01:27 +0100 From: Florian Westphal To: Visa Hankala Cc: Florian Westphal , Steffen Klassert , Herbert Xu , "David S. Miller" , netdev@vger.kernel.org Subject: Re: [PATCH] xfrm: Fix wraparound in xfrm_policy_addr_delta() Message-ID: <20201229160127.GA30823@breakpoint.cc> References: <20201229145009.cGOUak0JdKIIgGAv@hankala.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201229145009.cGOUak0JdKIIgGAv@hankala.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Visa Hankala wrote: > Use three-way comparison for address elements to avoid integer > wraparound in the result of xfrm_policy_addr_delta(). > > This ensures that the search trees are built and traversed correctly > when the difference between compared address elements is larger > than INT_MAX. Please provide an update to tools/testing/selftests/net/xfrm_policy.sh that shows that this is a problem. > switch (family) { > case AF_INET: > - if (sizeof(long) == 4 && prefixlen == 0) > - return ntohl(a->a4) - ntohl(b->a4); > - return (ntohl(a->a4) & ((~0UL << (32 - prefixlen)))) - > - (ntohl(b->a4) & ((~0UL << (32 - prefixlen)))); > + mask = ~0U << (32 - prefixlen); > + ma = ntohl(a->a4) & mask; > + mb = ntohl(b->a4) & mask; This is suspicious. Is prefixlen == 0 impossible? If not, then after patch mask = ~0U << 32; ... and function returns 0.