From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9740BC4363A for ; Thu, 29 Oct 2020 15:31:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41B1220724 for ; Thu, 29 Oct 2020 15:31:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728209AbgJ2PbT (ORCPT ); Thu, 29 Oct 2020 11:31:19 -0400 Received: from foss.arm.com ([217.140.110.172]:39332 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728347AbgJ2P3W (ORCPT ); Thu, 29 Oct 2020 11:29:22 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B142C1063; Thu, 29 Oct 2020 08:29:21 -0700 (PDT) Received: from e113632-lin (e113632-lin.cambridge.arm.com [10.1.194.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 450763F66E; Thu, 29 Oct 2020 08:29:20 -0700 (PDT) References: <20201029151103.373410-1-colin.king@canonical.com> User-agent: mu4e 0.9.17; emacs 26.3 From: Valentin Schneider To: Colin King Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] sched/debug: fix memory corruption caused by multiple small reads of flags In-reply-to: <20201029151103.373410-1-colin.king@canonical.com> Date: Thu, 29 Oct 2020 15:29:18 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/10/20 15:11, Colin King wrote: > Detected by running 'stress-ng --procfs 0' on 5.10-rc1; example splat: > That's definitely what I'll need to run next time I lay my dirty hands on procfs. > Link: https://bugzilla.kernel.org/show_bug.cgi?id=209919 > Reported-by: Jeff Bastian > Fixes: 5b9f8ff7b320 ("sched/debug: Output SD flag names rather than their values") > Signed-off-by: Colin Ian King Reviewed-by: Valentin Schneider > --- > kernel/sched/debug.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c > index 0655524..2357921 100644 > --- a/kernel/sched/debug.c > +++ b/kernel/sched/debug.c > @@ -251,7 +251,7 @@ static int sd_ctl_doflags(struct ctl_table *table, int write, > unsigned long flags = *(unsigned long *)table->data; > size_t data_size = 0; > size_t len = 0; > - char *tmp; > + char *tmp, *buf; > int idx; > > if (write) > @@ -269,17 +269,17 @@ static int sd_ctl_doflags(struct ctl_table *table, int write, > return 0; > } > > - tmp = kcalloc(data_size + 1, sizeof(*tmp), GFP_KERNEL); [...] > - tmp += *ppos; [...] > - kfree(tmp); Yeah, that's downright sloppy :( I can't remember which one it was in a hurry, but I was "inspired" by another proc handler somewhere; I'll try to find out if there's any issue in that one or if I really cannot shift the blame elsewhere.