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=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no 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 4FEC8C433E2 for ; Mon, 14 Sep 2020 11:47:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B7B6A21741 for ; Mon, 14 Sep 2020 11:47:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="LMoGgSjo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B7B6A21741 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2D1836B0055; Mon, 14 Sep 2020 07:47:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25A366B005A; Mon, 14 Sep 2020 07:47:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 122E06B005C; Mon, 14 Sep 2020 07:47:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id EDADB6B0055 for ; Mon, 14 Sep 2020 07:47:14 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id AD6A9845E326 for ; Mon, 14 Sep 2020 11:47:14 +0000 (UTC) X-FDA: 77261491188.14.bean80_560b9ed27108 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 7DE6B18229818 for ; Mon, 14 Sep 2020 11:47:14 +0000 (UTC) X-HE-Tag: bean80_560b9ed27108 X-Filterd-Recvd-Size: 5075 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 11:47:13 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id d9so12415920pfd.3 for ; Mon, 14 Sep 2020 04:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PJJFfsXoL3LK4g3p5cL7uzGgHtTaKv/IoQGqOUptDbk=; b=LMoGgSjo/62BmNodRWPJOdh8Q7bYP3tBTm1Td+5oc2sRIrUVS6tveSb3pEQ+9NoNMU fvMnZkauo2lzC5L+bKV27PfBYAsIAldo0wtm8s4znd1aebcNyMyCWGiEVYMzS7i8bWC3 i5dCVawJOXVg0YuNR/pjmkLgZMz54RqOVNEjRHvNYTpRlpkeqQF5aqzg4ERgZBifoG7X Y4qo/2/M1Ntc37rVLnQVCJuTKcUnr510/+mScEEvSJgMPMtykWDAIAmOge68yAeSbERN Jd5kVxs3lzLjFhIpZv8gqRiaXIR76JQSY7fVL0Z5+xYW+LX8O5KnOC/FjhsrmMCyAqxz IeVg== 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=PJJFfsXoL3LK4g3p5cL7uzGgHtTaKv/IoQGqOUptDbk=; b=sF2bnnH9itqKtYegLU6O5RFdfA3iVoZSa9WDDf2P5aRI/zrGeqztTVkKIJ+MyK/5lU 2aGZGPHqVxlyx7dok1DIGPnHC/gSCtK/PbL44SILSGW2qMWSlMEGBzHEgJwF0KyJPxvX jj6d5I3Awxir+JXwpyC0uixgldeJfIYetpFmqyakm6aaywvDUgq+0QV9gtL9p2qvJRdL Stp6dDam6AsKzTsJnO/cfR2lEnGUZ19qrlBmVkZL7MpR0BsBTSCNt9t4+bYMDGRDX+S2 9OXy/mM4UqUmBYSWsEiIRKTKGkdKV4QXwAFxaVWs8Zj8u4JXHZNZ5ZOadtTbzMiyxjc7 BnjA== X-Gm-Message-State: AOAM530XTAP8CAEcys7LRIQ35UcAVnWac2tkyHUNlbK5hQah5QcmqKz/ ZQ0C6fvBVSW/lB6fp/wOx/YrGQdldfOjqmCS8pbxcA== X-Google-Smtp-Source: ABdhPJyjND+eSy82UJKuklU4sT9+Zf+lGuuR32yG+mG5u1LFcj1veM/R7jIcv7XuT1WF8+Qc6dxq4dxdcJqRrMgZJGA= X-Received: by 2002:a63:3047:: with SMTP id w68mr10335591pgw.341.1600084032707; Mon, 14 Sep 2020 04:47:12 -0700 (PDT) MIME-Version: 1.0 References: <20200912155100.25578-1-songmuchun@bytedance.com> <20200912174241.eeaa771755915f27babf9322@linux-foundation.org> <20200914091844.GE16999@dhcp22.suse.cz> <20200914103205.GI16999@dhcp22.suse.cz> In-Reply-To: <20200914103205.GI16999@dhcp22.suse.cz> From: Muchun Song Date: Mon, 14 Sep 2020 19:46:36 +0800 Message-ID: Subject: Re: [External] Re: [PATCH] mm: memcontrol: Fix out-of-bounds on the buf returned by memory_stat_format To: Michal Hocko Cc: Andrew Morton , Johannes Weiner , Vladimir Davydov , Cgroups , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 7DE6B18229818 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: On Mon, Sep 14, 2020 at 6:32 PM Michal Hocko wrote: > > On Mon 14-09-20 17:43:42, Muchun Song wrote: > > On Mon, Sep 14, 2020 at 5:18 PM Michal Hocko wrote: > > > > > > On Mon 14-09-20 12:02:33, Muchun Song wrote: > > > > On Sun, Sep 13, 2020 at 8:42 AM Andrew Morton wrote: > > > > > > > > > > On Sat, 12 Sep 2020 23:51:00 +0800 Muchun Song wrote: > > > > > > > > > > > The memory_stat_format() returns a format string, but the return buf > > > > > > may not including the trailing '\0'. So the users may read the buf > > > > > > out of bounds. > > > > > > > > > > That sounds serious. Is a cc:stable appropriate? > > > > > > > > > > > > > Yeah, I think we should cc:stable. > > > > > > Is this a real problem? The buffer should contain 36 lines which makes > > > it more than 100B per line. I strongly suspect we are not able to use > > > that storage up. > > > > Before memory_stat_format() return, we should call seq_buf_putc(&s, '\0'). > > Otherwise, the return buf string has no trailing null('\0'). But users treat buf > > as a string(and read the string oob). It is wrong. Thanks. > > I am not sure I follow you. vsnprintf which is used by seq_printf will > add \0 if there is a room for that. And I argue there is a lot of room > in the buffer so a corner case where the buffer gets full doesn't happen > with the current code. Thanks for your explanation. Yeah, seq_printf will add \0 if there is a room for that. So I agree with you that the "Fixes" tag is wrong. There is nothing to fix. Sorry for the noise. I think that if someone uses seq_buf_putc(maybe in the feature) at the end of memory_stat_format(). It will break the rule and there is no \0. So this patch can just make the code robust but need to change the commit log and remove the Fixes tag. > -- > Michal Hocko > SUSE Labs -- Yours, Muchun