From patchwork Sat Sep 29 01:36:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 10620581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D7CB174A for ; Sat, 29 Sep 2018 01:36:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0704428FF5 for ; Sat, 29 Sep 2018 01:36:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEEC22BC6E; Sat, 29 Sep 2018 01:36:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6130828FF5 for ; Sat, 29 Sep 2018 01:36:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DBCC8E0002; Fri, 28 Sep 2018 21:36:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 68C258E0001; Fri, 28 Sep 2018 21:36:20 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57A598E0002; Fri, 28 Sep 2018 21:36:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by kanga.kvack.org (Postfix) with ESMTP id 248A18E0001 for ; Fri, 28 Sep 2018 21:36:20 -0400 (EDT) Received: by mail-yb1-f200.google.com with SMTP id p18-v6so13585ybe.0 for ; Fri, 28 Sep 2018 18:36:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:message-id:mime-version :subject:from:to:cc; bh=5i7Y5KMXl0/wZYNpCFu5wfVixx8o065kOMY75Ho546E=; b=LKAFtbjOiVM9M1KFBV0vleaYYrvpiwC8mqdIAqOjgvsFt61QF3bHyTqHt/kBmoHpPX wXdRAsfWncGsDNIu7HWnpy5EV/SEYgveUab8L2b8gBpE/Wk/Z/gUKOJ3qfM2L/+0kgYH GcidE9Gxza2zyNj6e+/fx48bhNlDEHV+C+q+4jk4tjFsXf1DbuKuHeebgcJQUxuoOwOp ox4d67g5fxp1pWekBin9Elx5RBdyFIT0x97CtsfrwBvPNPrCqd6WkWXfS3RqHNRKD/4O i5cGDTIb9Z2SHOthuGacVBL26WtJtDvRpZgOJsO3fFybuUamQ66ab8n7PWKZOOQx6Hq8 fAhw== X-Gm-Message-State: ABuFfog974Z20nzFmu+EdvxvquiisYHKUPR0JRCW8M8BNHG/YvWZ21rl PZAC8ziwqwRE1PVsmB6/vlMW4qhKvWjBzD9dYYRYL+MoHRIVW0VGPKSmPOTI7IMbjF6dUZQEQXF cHifE2oLBhE82Z6Anmv5nx8g4QiJIJLvhqjMquFMklCAR7NYXnE6x8T31vd8QqoB7ylwcrLINNK v3KTPJamGovs3xO1tsB3kc3RlsilsW4+DTxCx1pRDj2Xzm/SpHePOpLljayGyf7YIrU8Fq1m7wX t/CNUK5sGRNH5pjzACpLjsHki77kGqdWbe5bQ9rhJeBHzwA0S5ZV5E0x1Wm2SIhk9C0c4BzHBQg CRpljOziiOYzLYEepOW9a7MahASPOY7H2ikikCNb5ezUb18YoraLwv4BU/y8m3fAqajmeAttXsa z X-Received: by 2002:a25:a125:: with SMTP id z34-v6mr699900ybh.35.1538184979738; Fri, 28 Sep 2018 18:36:19 -0700 (PDT) X-Received: by 2002:a25:a125:: with SMTP id z34-v6mr699897ybh.35.1538184979131; Fri, 28 Sep 2018 18:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538184979; cv=none; d=google.com; s=arc-20160816; b=LCunMIcb7kWWI0d5DENC78o5gC8rKQ8O5jnpYtIuQ0za1ri8nwo59swQHwqCtYBnHx FwrSji4j2AD1SGtPcLRkKdRYCjNaI+pTbX1+1lJZTdun/F2lByW1qW9/MpOGtqaSCJdI 3PfQNyNMGktLMPHtxpMBHJnFa4fspYxJTauZaCrMkjZLSW+gKB/7qXcCoRoc5Sh8fUwS TFyFStnIMwL5nHAaRJ76L7dtLbNNB32X/Hi/JBFbdqTH8W57k67JLzFC5vEsrrAbaM4o NRRR9NurnyzEscQKDwLtcRUrkXYt/vVL1zWP3ztmuG9Oa5hy4TxUUipw8TI3EFMhIOaq 2G4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:mime-version:message-id:date:dkim-signature; bh=5i7Y5KMXl0/wZYNpCFu5wfVixx8o065kOMY75Ho546E=; b=AE2P2hgzT8qh+gsXwGYl1dl3JCtx452ItiXFCD1q1jTCFxBy134y4nDjcTgwDzaZVl ar+ue7Jw6ysDPjzL/LZr84CgifSixcyjf9YJXD1AlmoczDEOuNwdN7FvnWb4qDPlQ+vm n6Bo35i44xCihp8PONbhy3K9vRGO9391zuUBWwzHdaff8Yp9uZSdpB5gXuQGGRMdYRfu BmzZF7agf2fHs1BYtUYPlAV8kVhW9eo5krCh2iJJ2D8n9tmWGlgXgMb1adPMGuCltD+S JyhXdk4eQJcS6EjcRzpue412ZrWaKn60e42bSGZ7yrBY4f0AZqU83EvmXUK+WZsHJEJe 05RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TChkzkff; spf=pass (google.com: domain of 3eteuwwukcf8g7kkedlldib.9ljifkru-jjhs79h.lod@flex--jannh.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3EteuWwUKCF8G7KKEDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--jannh.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id k5-v6sor3628837ybd.71.2018.09.28.18.36.19 for (Google Transport Security); Fri, 28 Sep 2018 18:36:19 -0700 (PDT) Received-SPF: pass (google.com: domain of 3eteuwwukcf8g7kkedlldib.9ljifkru-jjhs79h.lod@flex--jannh.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TChkzkff; spf=pass (google.com: domain of 3eteuwwukcf8g7kkedlldib.9ljifkru-jjhs79h.lod@flex--jannh.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3EteuWwUKCF8G7KKEDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--jannh.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=5i7Y5KMXl0/wZYNpCFu5wfVixx8o065kOMY75Ho546E=; b=TChkzkff1STspvMgxNQxy+2PxlLl1YBcWJ64oeFo7Pz06zteGX8VnLa23oys1D5cR3 5le5kVj6BHhFc1YF77iXZ8AUVmlmTClGkEH+uQD3ALJG5rxB7HsW1Fv5GAixHEXvgvA0 T4xbelemf7hTDoOlRlVl0MOGSUaAm17ihzD51/LewB3cFY4gCr/NK5xkkXemEVm7u6fE iUov65PCADYYXClYh3cOyonSZfzphZrSXNk/rcYpEYz4OTHyVTSfOceTkEzc2uBGcXoI 6P4gIPDCEexcfQA5fQdEl+9k/CDWF9hMisDXnAOnLRw96uy0QJ5DV1x6iRjwU9PqYWuN S5cw== X-Google-Smtp-Source: ACcGV60shaojX2DK1XL6QYIMiothC8Cg2LXMQxTISxJvYCwCzjF0w0EUd/s5kA/QfpncYsahJ2tmhpmqEQ== X-Received: by 2002:a25:324e:: with SMTP id y75-v6mr1009276yby.4.1538184978885; Fri, 28 Sep 2018 18:36:18 -0700 (PDT) Date: Sat, 29 Sep 2018 03:36:11 +0200 Message-Id: <20180929013611.163130-1-jannh@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog Subject: [PATCH] mm/vmstat: fix outdated vmstat_text From: Jann Horn To: Andrew Morton , linux-mm@kvack.org, jannh@google.com Cc: Davidlohr Bueso , Oleg Nesterov , Linus Torvalds , Christoph Lameter , Roman Gushchin , Kemi Wang , Kees Cook X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP commit 7a9cdebdcc17 ("mm: get rid of vmacache_flush_all() entirely") removed the VMACACHE_FULL_FLUSHES statistics, but didn't remove the corresponding entry in vmstat_text. This causes an out-of-bounds access in vmstat_show(). Luckily this only affects kernels with CONFIG_DEBUG_VM_VMACACHE=y, which is probably very rare. Having two gigantic arrays that must be kept in sync isn't exactly robust. To make it easier to catch such issues in the future, add a BUILD_BUG_ON(). Fixes: 7a9cdebdcc17 ("mm: get rid of vmacache_flush_all() entirely") Cc: stable@vger.kernel.org Signed-off-by: Jann Horn Acked-by: Michal Hocko --- mm/vmstat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/vmstat.c b/mm/vmstat.c index 8ba0870ecddd..db6379a3f8bf 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1283,7 +1283,6 @@ const char * const vmstat_text[] = { #ifdef CONFIG_DEBUG_VM_VMACACHE "vmacache_find_calls", "vmacache_find_hits", - "vmacache_full_flushes", #endif #ifdef CONFIG_SWAP "swap_ra", @@ -1661,6 +1660,8 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos) stat_items_size += sizeof(struct vm_event_state); #endif + BUILD_BUG_ON(stat_items_size != + ARRAY_SIZE(vmstat_text) * sizeof(unsigned long)); v = kmalloc(stat_items_size, GFP_KERNEL); m->private = v; if (!v)