From patchwork Thu May 27 19:56:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 102766 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4RJvkeO020165 for ; Thu, 27 May 2010 19:57:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759604Ab0E0T5g (ORCPT ); Thu, 27 May 2010 15:57:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38482 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755488Ab0E0T5f (ORCPT ); Thu, 27 May 2010 15:57:35 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4RJvH5X010895 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 27 May 2010 15:57:17 -0400 Received: from tranklukator.englab.brq.redhat.com (dhcp-30-233.brq.redhat.com [10.34.30.233]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o4RJvEqe018288; Thu, 27 May 2010 15:57:15 -0400 Received: by tranklukator.englab.brq.redhat.com (nbSMTP-1.00) for uid 500 onestero@redhat.com; Thu, 27 May 2010 21:56:11 +0200 (CEST) Date: Thu, 27 May 2010 21:56:09 +0200 From: Oleg Nesterov To: Mike Frysinger , Andrew Morton Cc: David Howells , Roland McGrath , linux-sh@vger.kernel.org, Paul Mundt , uclinux-dist-devel@blackfin.uclinux.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] blackfin: ptrace: fix the unsafe usage of mm/find_vma in is_user_addr_valid() Message-ID: <20100527195609.GB25935@redhat.com> References: <20100521162659.GA16193@redhat.com> <20100521183512.4477F40476@magilla.sf.frob.com> <20100522165320.GA19573@redhat.com> <25539.1274711817@redhat.com> <20100524151445.GA6393@redhat.com> <17134.1274778852@redhat.com> <20100525102345.GA23574@redhat.com> <20100526124006.GA28358@redhat.com> <20100527195544.GA25935@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20100527195544.GA25935@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 27 May 2010 19:57:46 +0000 (UTC) --- 34-rc1/arch/blackfin/kernel/ptrace.c~IUAV_1_GET_MM_TAKE_SEM 2010-05-27 17:52:36.000000000 +0200 +++ 34-rc1/arch/blackfin/kernel/ptrace.c 2010-05-27 20:07:10.000000000 +0200 @@ -113,29 +113,40 @@ put_reg(struct task_struct *task, long r /* * check that an address falls within the bounds of the target process's memory mappings */ -static inline int is_user_addr_valid(struct task_struct *child, +static int is_user_addr_valid(struct task_struct *child, unsigned long start, unsigned long len) { + struct mm_struct *mm; struct vm_area_struct *vma; struct sram_list_struct *sraml; + int ret = 0; /* overflow */ if (start + len < start) return -EIO; + if (start >= FIXED_CODE_START && start + len < FIXED_CODE_END) + return 0; - vma = find_vma(child->mm, start); + mm = get_task_mm(child); + if (!mm) + return -EIO; + + down_read(&mm->mmap_sem); + vma = find_vma(mm, start); if (vma && start >= vma->vm_start && start + len <= vma->vm_end) - return 0; + goto out; - for (sraml = child->mm->context.sram_list; sraml; sraml = sraml->next) + for (sraml = mm->context.sram_list; sraml; sraml = sraml->next) if (start >= (unsigned long)sraml->addr && start + len < (unsigned long)sraml->addr + sraml->length) - return 0; + goto out; - if (start >= FIXED_CODE_START && start + len < FIXED_CODE_END) - return 0; + ret = -EIO; +out: + up_read(&mm->mmap_sem); + mmput(mm); - return -EIO; + return ret; } /*