From patchwork Thu Jun 27 07:04:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Po-Hsu Lin X-Patchwork-Id: 1123157 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Z9rr4hBmz9sN6; Thu, 27 Jun 2019 17:05:16 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1hgOT0-0001I6-Le; Thu, 27 Jun 2019 07:05:10 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1hgOSy-0001HY-7t for kernel-team@lists.ubuntu.com; Thu, 27 Jun 2019 07:05:08 +0000 Received: from mail-pl1-f199.google.com ([209.85.214.199]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hgOSx-0005pT-Oi for kernel-team@lists.ubuntu.com; Thu, 27 Jun 2019 07:05:07 +0000 Received: by mail-pl1-f199.google.com with SMTP id 71so908952pld.17 for ; Thu, 27 Jun 2019 00:05:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=0L50p/MVw/lOB5KQDmntpuzzcgfiUAOUUiqVlK5ionQ=; b=j+UtmLOdxULavrRvvGs2J3gUSY9GNkG+3hBYKtZFia+Ivvl3++mBgt372/siuSMQlj 4r6JRDw0DiP/JU+rz5uwAJn8FxQa8fWF5nDsMKH4Mr1A465M3rldmOsANttiKE+ju4Ar COh9HGpvHnMxIyY/8DhZlYd2fz88ArkhuMByjWIDOaAjUPU2R5xukenPRn5zoKtCLlx7 7VsiCmDDrSJMranh+Kexv78hyLm2Q0/5uhw1nme3WOizbU/H8eu1dxPRakdmod6QQQlV Myh+ShL9AtZ8v/YTVHaUSLs5kFDgXRXGt3YkT6hXqFoL7UKAV4hBPuVm8aZskua7O6Vv 0FvA== X-Gm-Message-State: APjAAAWsXE8bBLS0LRK0mtVWf2eQjBSCkCrKvoctTHhnFUT0o6/hHOqK 7bThZvR525tS6w7VuIELBa84A4M+unFzeoFtx52Lcm+anbt3Osr6KaalSw1o94izo80CDPxJlAA 5uzPbGH490GYD1mMNiPci8QlkJjwhliWNOBo1YReL X-Received: by 2002:a17:90a:2244:: with SMTP id c62mr4254370pje.29.1561619106176; Thu, 27 Jun 2019 00:05:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbqUuEC0Qw9rvxRkkBEP9no7mhc1BqNgWZ2LBFNq3H1CHbIrptMAKiH4q6aT3k1Ik/ea4VYA== X-Received: by 2002:a17:90a:2244:: with SMTP id c62mr4254342pje.29.1561619105895; Thu, 27 Jun 2019 00:05:05 -0700 (PDT) Received: from Leggiero.taipei.internal (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id 201sm2777722pfz.24.2019.06.27.00.05.04 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 00:05:05 -0700 (PDT) From: Po-Hsu Lin To: kernel-team@lists.ubuntu.com Subject: [B][C][SRU][PATCH 2/2] kernel/sysctl.c: fix out-of-bounds access when setting file-max Date: Thu, 27 Jun 2019 15:04:54 +0800 Message-Id: <20190627070454.18944-3-po-hsu.lin@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190627070454.18944-1-po-hsu.lin@canonical.com> References: <20190627070454.18944-1-po-hsu.lin@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Will Deacon BugLink: https://bugs.launchpad.net/bugs/1834310 Commit 32a5ad9c2285 ("sysctl: handle overflow for file-max") hooked up min/max values for the file-max sysctl parameter via the .extra1 and .extra2 fields in the corresponding struct ctl_table entry. Unfortunately, the minimum value points at the global 'zero' variable, which is an int. This results in a KASAN splat when accessed as a long by proc_doulongvec_minmax on 64-bit architectures: | BUG: KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax+0x5d8/0x6a0 | Read of size 8 at addr ffff2000133d1c20 by task systemd/1 | | CPU: 0 PID: 1 Comm: systemd Not tainted 5.1.0-rc3-00012-g40b114779944 #2 | Hardware name: linux,dummy-virt (DT) | Call trace: | dump_backtrace+0x0/0x228 | show_stack+0x14/0x20 | dump_stack+0xe8/0x124 | print_address_description+0x60/0x258 | kasan_report+0x140/0x1a0 | __asan_report_load8_noabort+0x18/0x20 | __do_proc_doulongvec_minmax+0x5d8/0x6a0 | proc_doulongvec_minmax+0x4c/0x78 | proc_sys_call_handler.isra.19+0x144/0x1d8 | proc_sys_write+0x34/0x58 | __vfs_write+0x54/0xe8 | vfs_write+0x124/0x3c0 | ksys_write+0xbc/0x168 | __arm64_sys_write+0x68/0x98 | el0_svc_common+0x100/0x258 | el0_svc_handler+0x48/0xc0 | el0_svc+0x8/0xc | | The buggy address belongs to the variable: | zero+0x0/0x40 | | Memory state around the buggy address: | ffff2000133d1b00: 00 00 00 00 00 00 00 00 fa fa fa fa 04 fa fa fa | ffff2000133d1b80: fa fa fa fa 04 fa fa fa fa fa fa fa 04 fa fa fa | >ffff2000133d1c00: fa fa fa fa 04 fa fa fa fa fa fa fa 00 00 00 00 | ^ | ffff2000133d1c80: fa fa fa fa 00 fa fa fa fa fa fa fa 00 00 00 00 | ffff2000133d1d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Fix the splat by introducing a unsigned long 'zero_ul' and using that instead. Link: http://lkml.kernel.org/r/20190403153409.17307-1-will.deacon@arm.com Fixes: 32a5ad9c2285 ("sysctl: handle overflow for file-max") Signed-off-by: Will Deacon Acked-by: Christian Brauner Cc: Kees Cook Cc: Alexey Dobriyan Cc: Matteo Croce Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds (cherry picked from commit 9002b21465fa4d829edfc94a5a441005cffaa972) Signed-off-by: Po-Hsu Lin --- kernel/sysctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 39ea0c1..df6492b 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -128,6 +128,7 @@ static int zero; static int __maybe_unused one = 1; static int __maybe_unused two = 2; static int __maybe_unused four = 4; +static unsigned long zero_ul; static unsigned long one_ul = 1; static unsigned long long_max = LONG_MAX; static int one_hundred = 100; @@ -1699,7 +1700,7 @@ static struct ctl_table fs_table[] = { .maxlen = sizeof(files_stat.max_files), .mode = 0644, .proc_handler = proc_doulongvec_minmax, - .extra1 = &zero, + .extra1 = &zero_ul, .extra2 = &long_max, }, {