From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 982DE70 for ; Fri, 30 Jul 2021 01:39:24 +0000 (UTC) Received: by mail-pj1-f51.google.com with SMTP id a4-20020a17090aa504b0290176a0d2b67aso18461592pjq.2 for ; Thu, 29 Jul 2021 18:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=vPAHzrcSpfKuQzB1lrV/ttkpcnRRhB/aWzazYKPR4LA=; b=Nkis4e8105uAbCge9aO+StXNkXelrJqOpF7xNsIBtcoe+D0iGfGrhXWOijeKDfFQS8 tcGIefv5L6ODB7FGlHuoK3nhQNiRzvNAcTkGvlhjpZKPls5MD5zfBf1pJ7Ll8rA8iZ5f LTaEoFLk38qAHkDnPefiooUaNHcHv32+03LBo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vPAHzrcSpfKuQzB1lrV/ttkpcnRRhB/aWzazYKPR4LA=; b=D0IMkxmYe6ogPLYOtXuYFC/pxKmeXR/wPiZQo3pKRX+so0k5d3UbX6sE8UVK5N2cAU SQf6DbwWPFT4WpiYL8MwAu8vMvy2H/xGNyO1VgE977+SdHLaAqhKzm3aKwOyMVDOVx9c Kq2vfX7xGOOOabFg+Dv25smJRG/UG0FLfM3xX1cu38HJ5lxp/MK3YVO3DLCYnIC5AfSI UmttEWIDqu+HHg4ZrdRJa849F5wupr9YkjxaMMMj9oEpBgx1d9QBUgmRHoPEKRXq0gKV 2RNF7lY86bZdYITPmIeC33D2ytyO8XIuulljfcz2qKhtZXzwy6QQ3VNsFFdOvrcMsbvn B5yg== X-Gm-Message-State: AOAM532kD2By+umv/smYbiolb7VCgKwh8IelEdUueZMZiFm5afHzia8r I9mghQGCN9rUNLAxZUTRgkzMIw== X-Google-Smtp-Source: ABdhPJzbwo1FmDrFDbiWZ8BWT3TYMS+pXDsYeTk5gfATiaIbAKAeZ3H6gw+DeJERV+7PZzePv9GaaQ== X-Received: by 2002:a63:1053:: with SMTP id 19mr5768pgq.395.1627609164105; Thu, 29 Jul 2021 18:39:24 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id z5sm97349pgz.77.2021.07.29.18.39.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jul 2021 18:39:23 -0700 (PDT) Date: Thu, 29 Jul 2021 18:39:22 -0700 From: Kees Cook To: Rasmus Villemoes Cc: Greg Kroah-Hartman , linux-hardening@vger.kernel.org, "Gustavo A. R. Silva" , Keith Packard , Andrew Morton , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-staging@lists.linux.dev, linux-block@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH 62/64] netlink: Avoid false-positive memcpy() warning Message-ID: <202107291838.25D1F118C@keescook> References: <20210727205855.411487-1-keescook@chromium.org> <20210727205855.411487-63-keescook@chromium.org> Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Jul 28, 2021 at 01:24:01PM +0200, Rasmus Villemoes wrote: > On 28/07/2021 07.49, Greg Kroah-Hartman wrote: > > On Tue, Jul 27, 2021 at 01:58:53PM -0700, Kees Cook wrote: > >> In preparation for FORTIFY_SOURCE performing compile-time and run-time > >> field bounds checking for memcpy(), memmove(), and memset(), avoid > >> intentionally writing across neighboring fields. > >> > >> Add a flexible array member to mark the end of struct nlmsghdr, and > >> split the memcpy() to avoid false positive memcpy() warning: > >> > >> memcpy: detected field-spanning write (size 32) of single field (size 16) > >> > >> Signed-off-by: Kees Cook > >> --- > >> include/uapi/linux/netlink.h | 1 + > >> net/netlink/af_netlink.c | 4 +++- > >> 2 files changed, 4 insertions(+), 1 deletion(-) > >> > >> diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h > >> index 4c0cde075c27..ddeaa748df5e 100644 > >> --- a/include/uapi/linux/netlink.h > >> +++ b/include/uapi/linux/netlink.h > >> @@ -47,6 +47,7 @@ struct nlmsghdr { > >> __u16 nlmsg_flags; /* Additional flags */ > >> __u32 nlmsg_seq; /* Sequence number */ > >> __u32 nlmsg_pid; /* Sending process port ID */ > >> + __u8 contents[]; > > > > Is this ok to change a public, userspace visable, structure? > > At least it should keep using a nlmsg_ prefix for consistency and reduce > risk of collision with somebody having defined an object-like contents > macro. But there's no guarantees in any case, of course. Ah, good call. I've adjusted this and added a comment. Thanks! -Kees -- Kees Cook