Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp224589rwe; Wed, 31 Aug 2022 20:29:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5X2qJJIsDEb76VIyUQe321IfCgakfxR43zLzEz52y3T7o1jA9wbwxaOLUtwW3fot24m5Yi X-Received: by 2002:a17:902:c401:b0:16f:b59:85a7 with SMTP id k1-20020a170902c40100b0016f0b5985a7mr28502278plk.115.1662002958041; Wed, 31 Aug 2022 20:29:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662002958; cv=none; d=google.com; s=arc-20160816; b=kniVEHjRnaFu/UtGYHEGbwp012ET16r6rSUJ6FdjgtwkFh2d9VJ1ojcpFiH0Wkkldf 52FZwu6X2A376kCuZ0VRB+lDqgup44Ms9lxhuZsZzDQ2A1CSUblXFpq+aAskWE39aPPH SOINnRQ8QEqBRMyuowmbdwutD23PusdZSjrlB4kTiDK2nnnZ1AWM19v40twybxUSHX+U 8BeR5E8bRpcYEg+VZZvRKEhxSREDthGxNPJsUzm/AtCOiGSHdRNXSNthTNkzOrimvg1x yJp6S2nECsmYhETMqLH0+xe5etrzAq+hKPCOz4dfqkD/3OWO9XaFf+xfrDdPZmru1UJ7 Xb7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=+Z3y4GXaKhpPDkoXaZLGH8xprkY7MpB53UX6bpm1+sA=; b=NRhu1S9h/MhnKSZNsopZm0pBLI/KljLEv2vHKjXjR2ibQYCBndZ5mFZq8P/RdcKLCR ZhZh7pZHtbENIfq7Qq5SNTYC4WL1xQLVp3Q2K+MumNLFPb+RBqhemyORPzihE0Obrg3l VhCUBHAFsezFXI9YZm6MgdRmOCGFQLCMEt2VqZkx9jM/pZhuNjmoFvbohohl5qtrML1L 5fA3qRRiD7YYGtPI69yBA0T6D3I9BCsnfqlMlBPmNcOr6l9LajLwUyDaoWRrNfEMTw/3 nFk6oU6mbZmXM939HheXE1VA9AR8t6lh5iM0XI7iy7g1tokNGHtiwOQB8K4Mj0Hrv7Sj 3RPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=A5YbaBMw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w69-20020a638248000000b0041d131d71e9si6603686pgd.827.2022.08.31.20.29.04; Wed, 31 Aug 2022 20:29:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=A5YbaBMw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232211AbiIADSd (ORCPT + 99 others); Wed, 31 Aug 2022 23:18:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbiIADS2 (ORCPT ); Wed, 31 Aug 2022 23:18:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 586C910F950; Wed, 31 Aug 2022 20:18:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E9C0F61DB4; Thu, 1 Sep 2022 03:18:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C837BC433D7; Thu, 1 Sep 2022 03:18:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662002306; bh=16dGpQuZWp80nNIsYZhnXMYclxOAATqFejwDvoEzOw4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=A5YbaBMwit/rAEULP1nMwye2THqInMMt1/CP/Mc7VAZgF1TO97g/9Y8yEVdFP53A4 Qix46e3cHJbpGJWAUkaqPE8JOwWmlFT6HxtNwsbC5Z5lQtydIMzN085iYO+OA8BMD2 uPNp9QJsgWUWBngDlPTPeKsNC7vMApA18SFVkFR0CMNVLwsAYIdfAOqMxKRk0q+t+v 74g2X5hxD4v9SQjlM1AsyfxXcPJFcbmGNtCaATgHGoEHSomb+cd748ebPyI8BhN16q kaekQvaDyWB5D/3J4P8x6btpDJJeeVZL/oxJn1k1p0jwk8PYmhoNVw+oeRebiujLgC OjxgwbP/bl8XA== Date: Wed, 31 Aug 2022 20:18:25 -0700 From: Jakub Kicinski To: Kees Cook Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , syzbot , Yajun Deng , netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Oliver Hartkopp , Harshit Mogalapalli , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH 1/2] netlink: Bounds-check nlmsg_len() Message-ID: <20220831201825.378d748d@kernel.org> In-Reply-To: <20220901030610.1121299-2-keescook@chromium.org> References: <20220901030610.1121299-1-keescook@chromium.org> <20220901030610.1121299-2-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 31 Aug 2022 20:06:09 -0700 Kees Cook wrote: > static inline int nlmsg_len(const struct nlmsghdr *nlh) > { > - return nlh->nlmsg_len - NLMSG_HDRLEN; > + u32 nlmsg_contents_len; > + > + if (WARN_ON_ONCE(check_sub_overflow(nlh->nlmsg_len, > + (u32)NLMSG_HDRLEN, > + &nlmsg_contents_len))) > + return 0; > + if (WARN_ON_ONCE(nlmsg_contents_len > INT_MAX)) > + return INT_MAX; > + return nlmsg_contents_len; We check the messages on input, making sure the length is valid wrt skb->len, and sane, ie > NLMSG_HDRLEN. See netlink_rcv_skb(). Can we not, pretty please? :(