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, 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 50CCBC433E2 for ; Mon, 14 Sep 2020 10:33:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B3B42076C for ; Mon, 14 Sep 2020 10:33:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726450AbgINKdM (ORCPT ); Mon, 14 Sep 2020 06:33:12 -0400 Received: from mx2.suse.de ([195.135.220.15]:58630 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726449AbgINKcZ (ORCPT ); Mon, 14 Sep 2020 06:32:25 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 23940AF49; Mon, 14 Sep 2020 10:32:24 +0000 (UTC) Date: Mon, 14 Sep 2020 12:32:05 +0200 From: Michal Hocko To: Muchun Song Cc: Andrew Morton , Johannes Weiner , Vladimir Davydov , Cgroups , Linux Memory Management List , LKML Subject: Re: [External] Re: [PATCH] mm: memcontrol: Fix out-of-bounds on the buf returned by memory_stat_format Message-ID: <20200914103205.GI16999@dhcp22.suse.cz> References: <20200912155100.25578-1-songmuchun@bytedance.com> <20200912174241.eeaa771755915f27babf9322@linux-foundation.org> <20200914091844.GE16999@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. -- Michal Hocko SUSE Labs From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michal Hocko Subject: Re: [External] Re: [PATCH] mm: memcontrol: Fix out-of-bounds on the buf returned by memory_stat_format Date: Mon, 14 Sep 2020 12:32:05 +0200 Message-ID: <20200914103205.GI16999@dhcp22.suse.cz> References: <20200912155100.25578-1-songmuchun@bytedance.com> <20200912174241.eeaa771755915f27babf9322@linux-foundation.org> <20200914091844.GE16999@dhcp22.suse.cz> Mime-Version: 1.0 Return-path: Content-Disposition: inline In-Reply-To: Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Muchun Song Cc: Andrew Morton , Johannes Weiner , Vladimir Davydov , Cgroups , Linux Memory Management List , LKML 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. -- Michal Hocko SUSE Labs