From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S970662AbdAEMBe (ORCPT ); Thu, 5 Jan 2017 07:01:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56354 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753005AbdAEMBZ (ORCPT ); Thu, 5 Jan 2017 07:01:25 -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, vbabka@suse.cz, kirill.shutemov@linux.intel.com, gerald.schaefer@de.ibm.com, hannes@cmpxchg.org, luto@kernel.org From: Jerome Marchand Message-ID: <7f0ce33d-2087-d80b-f64a-25b0e230e6e9@redhat.com> Date: Thu, 5 Jan 2017 13:01:11 +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: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="UA4x4EXTn8PUe0vrXWr2LqqaiCShWFkOo" X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 05 Jan 2017 12:01:26 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --UA4x4EXTn8PUe0vrXWr2LqqaiCShWFkOo Content-Type: multipart/mixed; boundary="XE9jXtEvQdRaHAExip5x1r2VNtavPhRfr"; protected-headers="v1" From: Jerome Marchand To: Richard Weinberger , linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, kirill.shutemov@linux.intel.com, gerald.schaefer@de.ibm.com, hannes@cmpxchg.org, luto@kernel.org Message-ID: <7f0ce33d-2087-d80b-f64a-25b0e230e6e9@redhat.com> Subject: Re: [PATCH] proc: Fix integer overflow of VmLib References: <20170104232918.25598-1-richard@nod.at> In-Reply-To: <20170104232918.25598-1-richard@nod.at> --XE9jXtEvQdRaHAExip5x1r2VNtavPhRfr Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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. >=20 > For the vast majority of all programs text size is smaller than exec_vm= =2E > 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. >=20 > 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. I guess returning 0 in such case is good enough, but the description of VmLib in Documentations/filesystems/proc.txt should be updated to warn users not to rely too much on this value. Jerome >=20 > Signed-off-by: Richard Weinberger > --- > fs/proc/task_mmu.c | 2 ++ > 1 file changed, 2 insertions(+) >=20 > 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 *m= m) > =20 > text =3D (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >>= 10; > lib =3D (mm->exec_vm << (PAGE_SHIFT-10)) - text; > + if ((long)lib < 0) > + lib =3D 0; > swap =3D get_mm_counter(mm, MM_SWAPENTS); > ptes =3D PTRS_PER_PTE * sizeof(pte_t) * atomic_long_read(&mm->nr_ptes= ); > pmds =3D PTRS_PER_PMD * sizeof(pmd_t) * mm_nr_pmds(mm); >=20 --XE9jXtEvQdRaHAExip5x1r2VNtavPhRfr-- --UA4x4EXTn8PUe0vrXWr2LqqaiCShWFkOo Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJYbjWHAAoJEHTzHJCtsuoCpVwH/jForSSpIbOZQdTwCU0G3ysn yKwzx7sawMixs1BM4REozRTJ/Hmyqe2lEeRW1TyCMqffv5+65R0Ro9Nq6Ouvhl65 l7umM8WfHkcuapPTfmy3BX87IJW8SWiuhrW7iDMrHaZomD/X3wltB39L87xEXl39 mDKHwZTmlaetcv57/UFiRhh+xXo6CPK1gI4lVd0cR5v0XrEmeAvz1iCMZ6kBeAB3 HuWfNOTkKaDQyULOTXbz5+aUQP0vpV9gx0tXfTgNqnHr2es1SUMPHndLaKaCUBqO cad/2OYyg6So6mR0SzYZfWx1xeoBdDh9yFQXU4wcJYp6vevfsgoKjc7wlBzY9oA= =wWLe -----END PGP SIGNATURE----- --UA4x4EXTn8PUe0vrXWr2LqqaiCShWFkOo--