Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2582773rdb; Mon, 4 Dec 2023 01:22:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0mAegTAc6H8CjjIbKfKCQFuxVtVpj32zx3VM6gHFx5RdN/BCE9lPAVI81S01tHgvRMpi9 X-Received: by 2002:a05:6870:356:b0:1fb:75a:c42c with SMTP id n22-20020a056870035600b001fb075ac42cmr3758760oaf.85.1701681754602; Mon, 04 Dec 2023 01:22:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701681754; cv=none; d=google.com; s=arc-20160816; b=bLXsTALnDRz+39u2YQt6toUIaK5z1citBwkjH4JnwXQccA7BKwfS5Q0E9D7inUVc5P CWLbsQtNYR+SMDRRGWQP1mhbc9r9eR8WSmwYVq12QOMwEHfgqJ2T+lpQSlkxQh6/7gwR BZHTgdPlmHu2t7WG4EXDIStHUwIZgsNVnBE1tFAQZT2oAYnhgASXE910gcbX0B6BryDJ L1QCj/41ruX2dXRrTBsWRhsIhm0NSTtIz0W6chz9HMj9YQGRj1lCz2ygwlPr6cuZhyKU AUTtnMnUdqtElf2OBEw515PPc5t9FKF9KOYLKiRhK8bz9npaKbXSRDYQXl6frQuDq44W g2cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :reply-to:user-agent:mime-version:date:message-id:dkim-signature; bh=Nr4Vt64RYXhRYcPjjM40iMIdhnoStkhytq2aXTjQ4Bk=; fh=xdE808kziwhztccYpPCAFJIJY/hSbPJE1NHIwE/w+os=; b=Ki9ixI5uemwjJ8guhh84a+KwIutH8009DQvU4WIfRs1aU6oeSEukn0jn7LmYYXsAwY wynZoxP3CjpiH2NXwahN7Hm3IfqK/LcGNDt79h1jX+RESpt4uUqY+zOZFX7e6/Y1237R drvGVBGe64lD9CIWA+abAgE+mrr5rrfIvmpnVclAZw9Cw65c3B4x4DfBTq3Ri3EkOS3K /vo8RDzVXSiH/BS2jSKCd2ary7OKiVCf0SWgEYUO6BN2UFvdiAD2r1XqwKBrtabkmZg/ FKH4riJAXRiEvhV8JHkdeEk7p80h3iHTWfm3eKIcLNTeS6ZJ7iVQbrugIglwGY8LFFFx wGDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@6wind.com header.s=google header.b=YFAyG4e+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=6wind.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e16-20020a656790000000b005c212bdc7d2si3577878pgr.611.2023.12.04.01.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 01:22:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@6wind.com header.s=google header.b=YFAyG4e+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=6wind.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id F02AF809E70D; Mon, 4 Dec 2023 01:22:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230046AbjLDJWX (ORCPT + 99 others); Mon, 4 Dec 2023 04:22:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229714AbjLDJWW (ORCPT ); Mon, 4 Dec 2023 04:22:22 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 578BBC3 for ; Mon, 4 Dec 2023 01:22:28 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40c09f4814eso12239175e9.1 for ; Mon, 04 Dec 2023 01:22:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; t=1701681747; x=1702286547; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:reply-to:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=Nr4Vt64RYXhRYcPjjM40iMIdhnoStkhytq2aXTjQ4Bk=; b=YFAyG4e+JoYvfq87anD5wXI7MDNUP1o5iCo8B9zjwfyqYxyRbtAxsOoeOYNmdBCR47 luQyyn9OQjL4Y/C/RdMNlqx8X+ZWEZQDcZzJmZ5NkFu8PgzA1YeVGM2jRD1ETBuijqcU lVsvRatKBYPL+uak+1G1CmIIwtZjLzurLUtP/2DJnp3u3m1zm9O2taYEjER3CWfLc4WF +g0F9rhgdC6RpvodY2gmW9yb9Jg7+vVd52fmtt+KCx9A4LT7sDtE3twba8g/VB7ifK1U vNcBebaHZhrMDidK4xkymw5tUkCu0GLRMS2WkHsf0McrxfE8N/AYsvXMMxS7kkKccIja CbBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701681747; x=1702286547; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:reply-to:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Nr4Vt64RYXhRYcPjjM40iMIdhnoStkhytq2aXTjQ4Bk=; b=Ukf5YNqT7jIs/IsOpEfCuYJUOR/6VcOdP4UZtwxishaqGi+7D27jwHHLyG+kcbeX/y jC6YeyTw/OPqnmDWRwJ1vZTsc4jmETmSBuwpfEPhppus3p1EjUCOJeBFw8SmtmoeWebj XZaW8/df5dwLpad1dKjSDRebGFmCRWo2YBYhRxEYeK2D6uRPI24t7rGaj7R7YzPGqNgo XWXiyajURqsaQf5I0ifCDJbnu44jLL2dgWnwMQuMtXc62AnQveVcRwcNv297azQ7AIwM TT1fyygMKJ/TrKl5UjoMk9veU85O0chSsGnp5Ul1HjtuRUb7TCXckAgcQQLOBolob69v O3WA== X-Gm-Message-State: AOJu0YxIPYGE25xkC9saWRosO3KANqWzmWSSWJSRQjjjPF92Cx3ijBWT 3SwQc+aVxAnRuP1htaz42qiQfg== X-Received: by 2002:a05:600c:acd:b0:40b:38a8:6c65 with SMTP id c13-20020a05600c0acd00b0040b38a86c65mr1664855wmr.26.1701681746784; Mon, 04 Dec 2023 01:22:26 -0800 (PST) Received: from ?IPV6:2a01:e0a:b41:c160:6cba:8826:daed:6772? ([2a01:e0a:b41:c160:6cba:8826:daed:6772]) by smtp.gmail.com with ESMTPSA id bg24-20020a05600c3c9800b0040b3d33ab55sm18093140wmb.47.2023.12.04.01.22.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Dec 2023 01:22:26 -0800 (PST) Message-ID: <95924d9e-b373-40fd-993c-25b0bae55e61@6wind.com> Date: Mon, 4 Dec 2023 10:22:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: nicolas.dichtel@6wind.com Subject: Re: [PATCH v2] netlink: Return unsigned value for nla_len() Content-Language: en-US To: Kees Cook , Jakub Kicinski Cc: kernel test robot , "David S. Miller" , Eric Dumazet , Paolo Abeni , Johannes Berg , Jeff Johnson , Michael Walle , Max Schulze , netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20231202202539.it.704-kees@kernel.org> From: Nicolas Dichtel Organization: 6WIND In-Reply-To: <20231202202539.it.704-kees@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 01:22:33 -0800 (PST) Le 02/12/2023 à 21:25, Kees Cook a écrit : > The return value from nla_len() is never expected to be negative, and can > never be more than struct nlattr::nla_len (a u16). Adjust the prototype > on the function. This will let GCC's value range optimization passes > know that the return can never be negative, and can never be larger than > u16. As recently discussed[1], this silences the following warning in > GCC 12+: > > net/wireless/nl80211.c: In function 'nl80211_set_cqm_rssi.isra': > net/wireless/nl80211.c:12892:17: warning: 'memcpy' specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=] > 12892 | memcpy(cqm_config->rssi_thresholds, thresholds, > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 12893 | flex_array_size(cqm_config, rssi_thresholds, > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 12894 | n_thresholds)); > | ~~~~~~~~~~~~~~ > > A future change would be to clamp the subtraction to make sure it never > wraps around if nla_len is somehow less than NLA_HDRLEN, which would > have the additional benefit of being defensive in the face of nlattr > corruption or logic errors. > > Reported-by: kernel test robot > Closes: https://lore.kernel.org/oe-kbuild-all/202311090752.hWcJWAHL-lkp@intel.com/ [1] > Cc: Jakub Kicinski > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Paolo Abeni > Cc: Johannes Berg > Cc: Jeff Johnson > Cc: Michael Walle > Cc: Max Schulze > Cc: netdev@vger.kernel.org > Cc: linux-wireless@vger.kernel.org > Signed-off-by: Kees Cook > --- > v2: > - do not clamp return value (kuba) > - adjust NLA_HDRLEN to be u16 also > v1: https://lore.kernel.org/all/20231130200058.work.520-kees@kernel.org/ > --- > include/net/netlink.h | 2 +- > include/uapi/linux/netlink.h | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/net/netlink.h b/include/net/netlink.h > index 83bdf787aeee..7678a596a86b 100644 > --- a/include/net/netlink.h > +++ b/include/net/netlink.h > @@ -1200,7 +1200,7 @@ static inline void *nla_data(const struct nlattr *nla) > * nla_len - length of payload > * @nla: netlink attribute > */ > -static inline int nla_len(const struct nlattr *nla) > +static inline u16 nla_len(const struct nlattr *nla) > { > return nla->nla_len - NLA_HDRLEN; > } > diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h > index f87aaf28a649..270feed9fd63 100644 > --- a/include/uapi/linux/netlink.h > +++ b/include/uapi/linux/netlink.h > @@ -247,7 +247,7 @@ struct nlattr { > > #define NLA_ALIGNTO 4 > #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1)) > -#define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr))) > +#define NLA_HDRLEN ((__u16) NLA_ALIGN(sizeof(struct nlattr))) I wonder if this may break the compilation of some userspace tools with errors like comparing signed and unsigned values. Regards, Nicolas