From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760865AbdAEIim (ORCPT ); Thu, 5 Jan 2017 03:38:42 -0500 Received: from mx2.suse.de ([195.135.220.15]:51324 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758048AbdAEIie (ORCPT ); Thu, 5 Jan 2017 03:38:34 -0500 Subject: Re: [PATCH] proc: Fix integer overflow of VmLib To: Richard Weinberger , linux-kernel@vger.kernel.org References: <20170104232918.25598-1-richard@nod.at> Cc: akpm@linux-foundation.org, mhocko@suse.com, kirill.shutemov@linux.intel.com, jmarchan@redhat.com, gerald.schaefer@de.ibm.com, hannes@cmpxchg.org, luto@kernel.org From: Vlastimil Babka Message-ID: <648b31b0-1c87-6d3d-addd-bd1c0e5ea421@suse.cz> Date: Thu, 5 Jan 2017 09:38:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20170104232918.25598-1-richard@nod.at> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/05/2017 12:29 AM, Richard Weinberger wrote: > /proc//status can report extremely high VmLib values which > will confuse monitoring tools. > VmLib is mm->exec_vm minus text size, where exec_vm is the number of > bytes backed by an executable memory mapping and text size is > mm->end_code - mm->start_code as set up by binfmt. > > For the vast majority of all programs text size is smaller than exec_vm. > But if a program interprets binaries on its own the calculation result > can be negative. > UserModeLinux is such an example. It installs and removes lots of PROT_EXEC > mappings but mm->start_code and mm->start_code remain and VmLib turns > negative. > > Fix this by detecting the overflow and just return 0. > For interpreting the value reported by VmLib is anyway useless but > returning 0 does at least not confuse userspace. > > Signed-off-by: Richard Weinberger Acked-by: Vlastimil Babka > --- > fs/proc/task_mmu.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index 8f96a49178d0..220091c29aa6 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -46,6 +46,8 @@ void task_mem(struct seq_file *m, struct mm_struct *mm) > > text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10; > lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text; > + if ((long)lib < 0) > + lib = 0; > swap = get_mm_counter(mm, MM_SWAPENTS); > ptes = PTRS_PER_PTE * sizeof(pte_t) * atomic_long_read(&mm->nr_ptes); > pmds = PTRS_PER_PMD * sizeof(pmd_t) * mm_nr_pmds(mm); >