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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B3B7C77B76 for ; Wed, 19 Apr 2023 03:33:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231400AbjDSDdX (ORCPT ); Tue, 18 Apr 2023 23:33:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbjDSDdW (ORCPT ); Tue, 18 Apr 2023 23:33:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E1AC40FE for ; Tue, 18 Apr 2023 20:33:20 -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 8316363A7F for ; Wed, 19 Apr 2023 03:33:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65DD7C433EF; Wed, 19 Apr 2023 03:33:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681875199; bh=WYqhr0gs0QI/S7bZ3TkzeQ+0TQymyEs7MY0s9TRTXns=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=u30Yw7ZnMRcJXGMJTytzKW4E/t4qTzITwN0VHdGCjbiLuuMblC6DAmOmsSuRKR61G qeXg42PxiGpMB/W3eYhkqRIguuzzM8+I9f6ZD/hFvn4bzF/G2iq3kHOvOoGiA1ylE2 cnwhR3B9XgayQ/PJzDvtDZO3E+zzCJlaSHvXNONDw4/UVEz1QyrwsKe6djXyvV0NN3 XZgVVMoDA39ZVyAq8YVYJFNLfFCCBoWO6FhpbxAqbuI1BiF3FlxfvuD7F4i4FAVfoY 90H2iymFMLPeoWNRCvQWDYNZevoagtJpl1L55GkA8GjYFjxyGODbvhI8ewsiuaccvJ OHBKk6OOYhkyg== Date: Tue, 18 Apr 2023 20:33:18 -0700 From: Jakub Kicinski To: Kuniyuki Iwashima Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Patrick McHardy , Pablo Neira Ayuso , Christophe Ricard , Johannes Berg , David Ahern , Kuniyuki Iwashima , , Brad Spencer Subject: Re: [PATCH v1 net] netlink: Use copy_to_user() for optval in netlink_getsockopt(). Message-ID: <20230418203318.2053c4f9@kernel.org> In-Reply-To: <20230419004246.25770-1-kuniyu@amazon.com> References: <20230419004246.25770-1-kuniyu@amazon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, 18 Apr 2023 17:42:46 -0700 Kuniyuki Iwashima wrote: > Brad Spencer provided a detailed report that when calling getsockopt() > for AF_NETLINK, some SOL_NETLINK options set only 1 byte even though such > options require more than int as length. > > The options return a flag value that fits into 1 byte, but such behaviour > confuses users who do not strictly check the value as char. > > Currently, netlink_getsockopt() uses put_user() to copy data to optlen and > optval, but put_user() casts the data based on the pointer, char *optval. > So, only 1 byte is set to optval. > > To avoid this behaviour, we need to use copy_to_user() or cast optval for > put_user(). > > Now getsockopt() accepts char as optval as the flags are only 1 byte. I think it's worth doing, but it will change the return value on big endian, right?