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 BA8DBC77B73 for ; Wed, 19 Apr 2023 17:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232144AbjDSRvV (ORCPT ); Wed, 19 Apr 2023 13:51:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbjDSRvU (ORCPT ); Wed, 19 Apr 2023 13:51:20 -0400 Received: from smtp-fw-9103.amazon.com (smtp-fw-9103.amazon.com [207.171.188.200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9305B194 for ; Wed, 19 Apr 2023 10:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1681926679; x=1713462679; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=URbjtbZEgM1ALlRRY15GL/JCWHb9BUrNKoK/uxS0MQc=; b=Y2r3/eYn3mXt5sxQBpl5uuT845JYHEei3+uFWHh3gskOOoBGzdJZz6Ex 92iRn8vIjPRtWVu6xpLNFXs3Rqfy316bi33XvZsZdnBLLc2MPoyKF6/md rpgJvRi9ZUhDwFHp4eEroGuwENnxcfEncrUXDqafmvU/gx9nAGlYi8D+d c=; X-IronPort-AV: E=Sophos;i="5.99,208,1677542400"; d="scan'208";a="1124116796" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-a65ebc6e.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2023 17:51:11 +0000 Received: from EX19MTAUWA002.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1e-m6i4x-a65ebc6e.us-east-1.amazon.com (Postfix) with ESMTPS id 4460D636D4; Wed, 19 Apr 2023 17:51:06 +0000 (UTC) Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 19 Apr 2023 17:50:55 +0000 Received: from 88665a182662.ant.amazon.com (10.187.170.33) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 19 Apr 2023 17:50:52 +0000 From: Kuniyuki Iwashima To: CC: , , , , , , , , , , , Subject: Re: [PATCH v1 net] netlink: Use copy_to_user() for optval in netlink_getsockopt(). Date: Wed, 19 Apr 2023 10:50:43 -0700 Message-ID: <20230419175043.37093-1-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230418203318.2053c4f9@kernel.org> References: <20230418203318.2053c4f9@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.187.170.33] X-ClientProxiedBy: EX19D038UWB003.ant.amazon.com (10.13.139.157) To EX19D004ANA001.ant.amazon.com (10.37.240.138) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jakub Kicinski Date: Tue, 18 Apr 2023 20:33:18 -0700 > 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? Ah, I missed that point, yes. I hope big endian users always initialise the value to avoid the tricky behaviour.