Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp557937pxa; Fri, 14 Aug 2020 11:14:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmkYAFwa0107M8DyLaMNU80auoh38FJ2sbwjk7fWn20BY7rZI3yrevZbVxGXSrnRPSLAgf X-Received: by 2002:a17:906:1589:: with SMTP id k9mr3548713ejd.115.1597428860741; Fri, 14 Aug 2020 11:14:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597428860; cv=none; d=google.com; s=arc-20160816; b=HbT8ccjCk7613iAhyAAvzsYcG8opl2h7enyCeyl9YbE4seZ7tBu9CiJlErgC920vTJ EHtuq9I6FkG+fbCrxJoeS4TZLKehzSWNHRrZxnC2FzwrG1NsXx/4xmMaDNhuZLjcUwLX OeggES93FMcfY657M3/m/Qj+N2VX+xsOz0/7L4Z64JCkQhs6Ts8GbPLNZi+SsoIMWnUb 8RTaWW/THDNavn7qaeMpOUuFtZlgVpj1KVgtSQzdMj+cDyT3IgGj4zFis9o/bT2UiKPk gC30ND3xrTmucZ8c31dIiPKoMy+ypCYTKn/MOA0ntDI9QViwmjW1jiaJ3qhKYMwdlayo E08g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=122t3jzal6R3JaxMo4XpEsSDimGG1Gv1Cqy1Hgw5644=; b=dqPhCm0CGCo1uj8lDlKPZCZCdauHWQOGXHWxaT2DeFsv444Am7HleP9twJ6FBg2jD6 qtC5C6wqQ+nNwM/wKBslL4r4R6Op2pDzt0zM8kkp3QPJmDB5S912G5pK/PP/Orl+nbwU yV3RWd/Pbx6KFWM5WOjQZJV+UE/iHGqnwrxofAIg2RtlVKQFBqetxgwWFGc546/3dzsd LypLpxJ4AEcOYd12Uoa0+zxsuvzli2oHjaDyUePvBH4TZkM1nA01/c599vRWblpM3ZGy XqQFa/UKm4QbotLsoGFOms2sYgPyml5RfwqnQNlPrwtrIyKibFTqKKf8CgC8V52tbUtA zf0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="1xJwF7/Z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e9si5570216edq.67.2020.08.14.11.13.55; Fri, 14 Aug 2020 11:14:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="1xJwF7/Z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727895AbgHNQm1 (ORCPT + 99 others); Fri, 14 Aug 2020 12:42:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:36532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726796AbgHNQmZ (ORCPT ); Fri, 14 Aug 2020 12:42:25 -0400 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2F4CD20855 for ; Fri, 14 Aug 2020 16:42:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597423344; bh=d9BdbP4v4mPSDocV/X8+coEoeF/GEtkKDXHdvTvLuJs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=1xJwF7/Z5fXekgvEA4/s8tnI3lcrFDZ98TP7EG6yuS8XsxBej+56+3k6/PMJkPC58 y3qZKfLadclxFXM4dqw4Rwm1JMXDpFOx8VVUY5jg5ea8IX+IbDD9/2DjKVbfP9fcib inC92fPJcUFr6vRgYO5d8mZLHIljXZj+HQgN9m60= Received: by mail-wr1-f51.google.com with SMTP id l2so8891941wrc.7 for ; Fri, 14 Aug 2020 09:42:24 -0700 (PDT) X-Gm-Message-State: AOAM5337+yUzRFpIaGcZQEsKHYFM9l17H7pHMPmDoipRfxzXtMBg7eYy 8jstQhwBfOh07SnHRtoxWVc2HvdpWGCWHTYw2fE6AQ== X-Received: by 2002:adf:e90f:: with SMTP id f15mr3538919wrm.18.1597423342736; Fri, 14 Aug 2020 09:42:22 -0700 (PDT) MIME-Version: 1.0 References: <87y2onbdtb.fsf@nanos.tec.linutronix.de> <8E41B15F-D567-4C52-94E9-367015480345@amacapital.net> <20200616132705.GW2531@hirez.programming.kicks-ass.net> <20200617131742.GD8389@yuki.lan> <20200812093114.GA13676@yuki.lan> <20200814145823.GA13646@yuki.lan> In-Reply-To: <20200814145823.GA13646@yuki.lan> From: Andy Lutomirski Date: Fri, 14 Aug 2020 09:42:11 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [LTP] [x86/entry] 2bbc68f837: ltp.ptrace08.fail To: Cyril Hrubis Cc: Andy Lutomirski , Peter Zijlstra , Alexandre Chartre , kernel test robot , LKML , lkp@lists.01.org, Thomas Gleixner , ltp@lists.linux.it Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 14, 2020 at 7:58 AM Cyril Hrubis wrote: > > Hi! > > > do_debug is a bit of a red herring here. ptrace should not be able to > > > put a breakpoint on a kernel address, period. I would just pick a > > > fixed address that's in the kernel text range or even just in the > > > pre-KASLR text range and make sure it gets rejected. Maybe try a few > > > different addresses for good measure. > > > > I've looked at the code and it seems like this would be a bit more > > complicated since the breakpoint is set by an accident in a race and the > > call still fails. Which is why the test triggers the breakpoint and > > causes infinite loop in the kernel... > > > > I guess that we could instead read back the address with > > PTRACE_PEEKUSER, so something as: > > > > > > break_addr = ptrace(PTRACE_PEEKUSER, child_pid, > > (void *)offsetof(struct user, u_debugreg[0]), > > NULL); > > > > if (break_addr == kernel_addr) > > tst_res(TFAIL, "ptrace() set break on a kernel address"); > > So this works actually nicely, even better than the original code. > > Any hints on how to select a fixed address in the kernel range as you > pointed out in one of the previous emails? I guess that this would end > up as a per-architecture mess of ifdefs if we wanted to hardcode it. > It's fundamentally architecture dependent. Sane architectures like s390x don't even have this concept. --Andy