Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp868569rwd; Thu, 8 Jun 2023 08:47:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6SSzhfF8Pm2iVwpD97r/CitEHdqKFrCmjbtrH8mM4NGFV5dzko1NUj+e4j/eQYOe5hHu9B X-Received: by 2002:a17:902:e811:b0:1ad:ddf0:131f with SMTP id u17-20020a170902e81100b001adddf0131fmr5816240plg.51.1686239269904; Thu, 08 Jun 2023 08:47:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686239269; cv=none; d=google.com; s=arc-20160816; b=ZU5i/F8eUekDjhH3n4/DzpmBBYkq6z6XG7dfYG5nbHO9r0Exi4ed76K9Tj9EPjT3W1 Ucsn6G1FDW4x1An1ttbHQOGvLItGoT64X6ofUr2rrfxjdmk5EzEXCP/Zi8UUvZ05nmtN hy414LIylB+Ec5OUlEBDFvN2315YmSHKr9xAMTqBpu01CLDHgQru2X445dZYgoIwn+Od vN8GIWKk5/USvNElIBAKAPwLw3s1tFAKucIvsixUB2uKTSF4rZ2lVNP1JAv7NJZsCKo4 dDEHM4+fWrAeLC7Q5Y4Fpqzd2JjgIagu3As/xaF+RwaWDdJ6fahmjjJaA/UNpSl+0Cse PhhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=YjexGMdyJWeBEjd6xCsB5dyXSs2Z5hB+eEW3odtxG74=; b=LYds0YYZ5jMW9V3xIhm4DYTvx229FxZscQLzGJel2Z6bL0VO+7H2UPi/pKDHXP+f9H BJa/XfqHsISPHog8+ObbxtT3nam8Uc0QSrAkw93BlPjHbQl32kWbzZIZw0lVtremQuQZ IN7tllJMYaeJ627kZrDR8hLb8yupLz4WRJVSVUaSMiMb3t95q4uNO73tpzpLXXPEJ6t5 6Apm90b2Uf+Y5TFaQMXO9bC8Ef36KX5SsOyNwL9v231FZttZFMTVWNUaxxIfCjaMIYcO efuIPrBRfUJLGhQPGy/4UwnRAtJKzhKpmscIl0eo336GkhvYEDdImpex9WGQYnnliqTV B5MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=SfueeyNY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l8-20020a170902f68800b001ac82e60516si1205009plg.323.2023.06.08.08.47.34; Thu, 08 Jun 2023 08:47:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=SfueeyNY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236691AbjFHP1t (ORCPT + 99 others); Thu, 8 Jun 2023 11:27:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234497AbjFHP1r (ORCPT ); Thu, 8 Jun 2023 11:27:47 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B42A172E; Thu, 8 Jun 2023 08:27:43 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 2496D1FDE6; Thu, 8 Jun 2023 15:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1686238062; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YjexGMdyJWeBEjd6xCsB5dyXSs2Z5hB+eEW3odtxG74=; b=SfueeyNYTBrTihKqx8oxJyfXgJUEO72qrEaWzKN9n/xvcrRpUuC7wTlr5iQ5JU20AoKVk+ RIlBFvY+Q+Do9PokOXqyijq2TF/CAdHol/tiqVodfAgEosBNsgNhjvbDhDhwUi/3kUlSxU tJXq1cRpat2EYGkHF7TOihaLs/AntV8= Received: from suse.cz (unknown [10.100.208.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 162EF2C141; Thu, 8 Jun 2023 15:27:41 +0000 (UTC) Date: Thu, 8 Jun 2023 17:27:40 +0200 From: Petr Mladek To: Kees Cook Cc: 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: References: <20230607223755.1610-1-richard@nod.at> <202306071634.51BBAFD14@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202306071634.51BBAFD14@keescook> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. I know there already are some WARN_ONs for similar situations, e.g. set_field_width() or set_precision(). But these do not get random values. And it would actually be nice to introduce something like INFO() that would be usable for these less serious problems where the backtrace is useful but they should never trigger panic(). > so this probably needs to be rearranged (or callers fixed). > Do we need to change the scanf API for sane use inside the kernel? It seems that userspace implementation of sscanf() and vsscanf() returns -ERANGE in this case. It might be a reasonable solution. Well, there is a risk of introducing security problems. The error value might cause an underflow/overflow when the caller does not expect a negative value. Alternative solution would be to update the "ip" code so that it reads the number separately and treat zero return value as -EINVAL. Best Regards, Petr