Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp399802yba; Fri, 5 Apr 2019 08:51:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJU8K8RqyGQaXFTZ7zviGV8FHu8FPYHCTjYGOSQiRl3uNhdUmq6Yw75Df2ho9LF3ES+uGs X-Received: by 2002:a17:902:a506:: with SMTP id s6mr13258476plq.164.1554479518040; Fri, 05 Apr 2019 08:51:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554479518; cv=none; d=google.com; s=arc-20160816; b=ifMCbqlU74ZSBKrQrmJNL45cmFG8eG9bUddz06P8Nh5bLR/Z5jBO/234LMcTwbXD7p PNSIXzx5T9PC9Bj5MGP4dsTYOt/+63sfz7mQyO6CAS7XahDB5crR7DwOOFZjaeydaYZv s3IeFg+Bory6u2h+L9578rkPVIpLGGuL/fN2kh7NMOvo1rVxHCK5X++K0PPdBbpR9iVz uwWpZ+CptZsGn718CLMqwOP07jTyw9//Y4ZzB5L2LuKOvYl3l138Qm91zTfbW99ehVgx TWQMf4kCxtycrj+oPI2yCwYRxzY2ovszM1BNdhzk9rNO23LVwCwEbrksnkAY3s4Gjlhk R6rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=L5oetkIZG68VNWmHkfR/Dw9MyRhI4MDOLdp/EBMOb1A=; b=c7lAHrVgf0twyavJRK7QpIzgXaAwv48I+YmzUkwk9UIynqqF/2SL7NV+IcDt8lzOWm sNfVSx6VaeiimpS3irWPRvRkf8qd/Dali1auJpboNd7w0dBz6cd9JwVZTV4/lOqtx8hT 0FoV7B0EWUOS3fSqe8IDH0ryAH4VK3ZSC7QMtnDN00vK5Z3Ose5YFxXx2mIDatBV6/Es tReGN2nYbZtdepOsV38iDLOzopchACREuy5ILgI5qhedXUUnlxSQAdJqtZ/+orYyf15c KCiILDDcf4evvzMP2ZXbH/Xqw4x9ipTJITCvjX6XROKZ9telPdjuX0oXQpg8sVu86v1G Mq/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="JWSC/NNc"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r190si20699450pfc.14.2019.04.05.08.51.42; Fri, 05 Apr 2019 08:51:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="JWSC/NNc"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731135AbfDEPtm (ORCPT + 99 others); Fri, 5 Apr 2019 11:49:42 -0400 Received: from mail-vs1-f65.google.com ([209.85.217.65]:37057 "EHLO mail-vs1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726730AbfDEPtl (ORCPT ); Fri, 5 Apr 2019 11:49:41 -0400 Received: by mail-vs1-f65.google.com with SMTP id w13so3772548vsc.4 for ; Fri, 05 Apr 2019 08:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=L5oetkIZG68VNWmHkfR/Dw9MyRhI4MDOLdp/EBMOb1A=; b=JWSC/NNcS/vfo9XVl1gVelgegdkriQ43+GdYvOZHbvazgHnSBJvWA5TsSYVaseq3eB 2ilxO0aNWGTqi0v4lAcyp5G2YHcIDbLqPBkcJLKa4Cv5jHyrj+mbtFeJBAb2Wgm2LvUP Gs3tOpQY3Jm8tSFE7isnovNyDUAskZ6YHgkdU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=L5oetkIZG68VNWmHkfR/Dw9MyRhI4MDOLdp/EBMOb1A=; b=ETWOERaijdJIobxaScjJXyqIcXUDPSVfbYFoLekvtjCUNrkaVT4FSk1MD0TyGjoBAj eUsC5ZBa3cE0ptaOkzbRot4MJ7z9tcQfqaR4byM+kjJsjIpgLCgschWLvd6OelUzd7ZP ji1sS3VAfwKUvSvdC/iLG0uwWc9s1ZNESdAfJ03+2qpHtVsYmGOCNhuMVoTZgasbTkKM HB3sa7Tgq1+lxTwidnl22X8NI936XTfLKAeTc9FVKWs5o238ntW/SleahYXrEGPtM5+M GXvNsA7xSn8QVP79MNi+UIrXfqlQpXS6IphRhsyOb/qkE+ICONjZ4ubtmTuugajP8LMC BFEA== X-Gm-Message-State: APjAAAULIj+Q5K/GhVbCVut2vLV0wwYTcpiDgEN39JsRS6/BON6ddgnw QNt/XV/gJLPoIIndAiSTo4O2YXh+/tU= X-Received: by 2002:a67:d38f:: with SMTP id b15mr8465036vsj.154.1554479379641; Fri, 05 Apr 2019 08:49:39 -0700 (PDT) Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com. [209.85.217.47]) by smtp.gmail.com with ESMTPSA id o197sm25217362vkf.27.2019.04.05.08.49.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Apr 2019 08:49:38 -0700 (PDT) Received: by mail-vs1-f47.google.com with SMTP id f22so3763256vso.7 for ; Fri, 05 Apr 2019 08:49:38 -0700 (PDT) X-Received: by 2002:a67:f04e:: with SMTP id q14mr8626492vsm.133.1554479377616; Fri, 05 Apr 2019 08:49:37 -0700 (PDT) MIME-Version: 1.0 References: <20190405065217.125140-1-houtao1@huawei.com> In-Reply-To: <20190405065217.125140-1-houtao1@huawei.com> From: Kees Cook Date: Fri, 5 Apr 2019 08:49:26 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] sysctl: redefine zero as a unsigned long To: Hou Tao Cc: "Luis R. Rodriguez" , LKML , "linux-fsdevel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 4, 2019 at 11:48 PM Hou Tao wrote: > > We have got KASAN splat when tried to set /proc/sys/fs/file-max: > > BUG: KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax+0x3e4/0x8f0 > Read of size 8 at addr ffff20000f9b2980 by task file-max.sh/36819 > > Call trace: > dump_backtrace+0x0/0x3f8 > show_stack+0x3c/0x60 > dump_stack+0x150/0x1a8 > print_address_description+0x2b8/0x5a0 > kasan_report+0x278/0x648 > __asan_load8+0x124/0x170 > __do_proc_doulongvec_minmax+0x3e4/0x8f0 > proc_doulongvec_minmax+0x80/0xa0 > proc_sys_call_handler+0x188/0x2a0 > proc_sys_write+0x5c/0x80 > __vfs_write+0x118/0x578 > vfs_write+0x184/0x418 > ksys_write+0xfc/0x1e8 > __arm64_sys_write+0x88/0xa8 > el0_svc_common+0x1a4/0x500 > el0_svc_handler+0xb8/0x180 > el0_svc+0x8/0xc > > The buggy address belongs to the variable: > zero+0x0/0x40 > > The cause is that proc_doulongvec_minmax() is trying to cast an int > pointer (namely &zero) to a unsigned long pointer, and dereferencing it. > > Although the warning seems does no harm, because zero will be placed > in a .bss section, but it's better to kill the KASAN warning by > redefining zero as a unsigned long, so it's OK whenever it is accessed > as an int or a a unsigned long. > > An alternative fix seems to be set the minimal value of file-max to be 1, > so one_ul can be used instead, but I'm not sure whether or not a file-max > with a value of zero has special purpose (e.g., prohibit the file-related > activities of all no-privileged users). > > Signed-off-by: Hou Tao Acked-by: Kees Cook -Kees > --- > kernel/sysctl.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/sysctl.c b/kernel/sysctl.c > index e5da394d1ca3..03846e015013 100644 > --- a/kernel/sysctl.c > +++ b/kernel/sysctl.c > @@ -124,7 +124,7 @@ static int sixty = 60; > > static int __maybe_unused neg_one = -1; > > -static int zero; > +static unsigned long zero; > static int __maybe_unused one = 1; > static int __maybe_unused two = 2; > static int __maybe_unused four = 4; > -- > 2.16.2.dirty > -- Kees Cook