From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED8363B407 for ; Thu, 8 Jun 2023 16:19:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D634BC433EF; Thu, 8 Jun 2023 16:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1686241175; bh=TOwT0GuJCz2bKXbQWOs8IqmDNX1diLd0cKOY/ea6+9g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TRW6izjx7+VO0YQ7ZXQ7nXFDTCyvOCxELhItwX4djo6jBb0usZ+WJ4ThHAzlHba9d z85IjLzhK3CoEMQXIt6RJkx3nDPQE+FmFRJpUNpIgFfizrchWjnEY6eNH6FQMyWiu1 23uqEAjCd0U4Dz0N5FLleaTbsVmKEbaZoS9WJjLk= Date: Thu, 8 Jun 2023 18:19:32 +0200 From: Greg KH To: Petr Mladek Cc: Kees Cook , Richard Weinberger , linux-hardening@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend Subject: Re: [RFC PATCH 0/1] Integer overflows while scanning for integers Message-ID: <2023060820-atom-doorstep-9442@gregkh> References: <20230607223755.1610-1-richard@nod.at> <202306071634.51BBAFD14@keescook> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Jun 08, 2023 at 05:27:40PM +0200, Petr Mladek wrote: > On Wed 2023-06-07 16:36:12, Kees Cook wrote: > > On Thu, Jun 08, 2023 at 12:37:54AM +0200, Richard Weinberger wrote: > > > Hi! > > > > > > Lately I wondered whether users of integer scanning functions check > > > for overflows. > > > To detect such overflows around scanf I came up with the following > > > patch. It simply triggers a WARN_ON_ONCE() upon an overflow. > > > > > > After digging into various scanf users I found that the network device > > > naming code can trigger an overflow. > > > > > > e.g: > > > $ ip link add 1 type veth peer name 9999999999 > > > $ ip link set name "%d" dev 1 > > > > > > It will trigger the following WARN_ON_ONCE(): > > > ------------[ cut here ]------------ > > > WARNING: CPU: 2 PID: 433 at lib/vsprintf.c:3701 vsscanf+0x6ce/0x990 > > > > Hm, it's considered a bug if a WARN or BUG can be reached from > > userspace, > > Good point. WARN() does not look like the right way in this case. > > Another problem is that some users use panic_on_warn. In this case, > the above "ip" command calls would trigger panic(). And it does not > look like an optimal behavior. "some users" == "most major cloud providers and a few billion Android phones" So in pure numbers, the huge majority of Linux systems running in the world have that option enabled. So please don't use WARN() to catch issues that can be triggered by userspace, that can cause data loss and worse at times. thanks, greg k-h