Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1950856AbdDYPop (ORCPT ); Tue, 25 Apr 2017 11:44:45 -0400 Received: from shards.monkeyblade.net ([184.105.139.130]:40976 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1950334AbdDYPof (ORCPT ); Tue, 25 Apr 2017 11:44:35 -0400 Date: Tue, 25 Apr 2017 11:44:33 -0400 (EDT) Message-Id: <20170425.114433.143144279134920277.davem@davemloft.net> To: glider@google.com Cc: dvyukov@google.com, kcc@google.com, edumazet@google.com, kuznet@ms2.inr.ac.ru, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH v2] net/packet: initialize val in packet_getsockopt() From: David Miller In-Reply-To: <20170424125914.43270-1-glider@google.com> References: <20170424125914.43270-1-glider@google.com> X-Mailer: Mew version 6.7 on Emacs 24.5 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Tue, 25 Apr 2017 08:03:10 -0700 (PDT) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 735 Lines: 19 From: Alexander Potapenko Date: Mon, 24 Apr 2017 14:59:14 +0200 > In the case getsockopt() is called with PACKET_HDRLEN and optlen < 4 > |val| remains uninitialized and the syscall may behave differently > depending on its value. This doesn't have security consequences (as the > uninit bytes aren't copied back), but it's still cleaner to initialize > |val| and ensure optlen is not less than sizeof(int). > > This bug has been detected with KMSAN. > > Signed-off-by: Alexander Potapenko > --- > v2: - if len < sizeof(int), make it 0 No, you should signal an error if the len is too small. Returning zero bytes to userspace silently makes the user think that he got the data he asked for.