Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755047Ab3JBSsX (ORCPT ); Wed, 2 Oct 2013 14:48:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26420 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753366Ab3JBSsW (ORCPT ); Wed, 2 Oct 2013 14:48:22 -0400 Date: Wed, 2 Oct 2013 20:48:03 +0200 From: Frantisek Hrbata To: "H. Peter Anvin" Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, tglx@linutronix.de, mingo@redhat.com, x86@kernel.org, oleg@redhat.com, kamaleshb@in.ibm.com, hechjie@cn.ibm.com, akpm@linux-foundation.org, dave.hansen@intel.com Subject: Re: [RESEND PATCH] x86: add phys addr validity check for /dev/mem mmap Message-ID: <20131002184803.GB2975@localhost.localdomain> Reply-To: Frantisek Hrbata References: <20131002160514.GA25471@localhost.localdomain> <524C5BFB.5050501@zytor.com> <20131002183155.GA2975@localhost.localdomain> <524C6799.9060800@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <524C6799.9060800@zytor.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2225 Lines: 66 On Wed, Oct 02, 2013 at 11:36:09AM -0700, H. Peter Anvin wrote: > On 10/02/2013 11:31 AM, Frantisek Hrbata wrote: > > On Wed, Oct 02, 2013 at 10:46:35AM -0700, H. Peter Anvin wrote: > >> On 10/02/2013 09:05 AM, Frantisek Hrbata wrote: > >>> + > >>> +int valid_phys_addr_range(phys_addr_t addr, size_t count) > >>> +{ > >>> + return addr + count <= __pa(high_memory); > >>> +} > >>> + > >>> +int valid_mmap_phys_addr_range(unsigned long pfn, size_t count) > >>> +{ > >>> + resource_size_t addr = (pfn << PAGE_SHIFT) + count; > >>> + return phys_addr_valid(addr); > >>> +} > >>> > >> > >> The latter has overflow problems. > > > > Could you please specify what overflow problems do you mean? > > Consider if pfn + count overflows and wraps around, or if (pfn << > PAGE_SHIFT) pushes bits out to the left. Ok, maybe I'm missing something, but isn't this handled in do_mmap_pgoff? /* offset overflow? */ if ((pgoff + (len >> PAGE_SHIFT)) < pgoff) return -EOVERFLOW; Anyway I can take a closer look and if this can really happen I can fix it. > > >> The former I realize matches the current /dev/mem, but it is still just > >> plain wrong in multiple ways. > > > > I guess that you are talking about /dev/mem implementation generelly, because > > this patch is exactly the same as the first one. All I'm trying to do here is to > > fix this simple problem, which was reported by a customer, using IMHO the least > > invasive way. Anyway is there any description what is wrong with /dev/mem > > implementation? Maybe I can try to take a look. > > > > The bottom line is that read/write to /dev/mem should be able to access > the same memory that we can mmap(). Having two different tests is > ridiculous. Ok, I can try to look into this. I just want to point out that some other archs like arm are doing it the same way. I simply replaced the generic check functions in drivers/char/mem.c with x86 specific ones. Thanks > > -hpa > > -- Frantisek Hrbata -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/