Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp458924ybk; Sat, 9 May 2020 07:59:39 -0700 (PDT) X-Google-Smtp-Source: APiQypJpADkdEi8uHkGEL18hanxi3ecIoc5TQleqMDYKTP9slSe5rXbuONjGjzubNBUD7Hfvir72 X-Received: by 2002:a05:6402:100b:: with SMTP id c11mr1465721edu.192.1589036379228; Sat, 09 May 2020 07:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589036379; cv=none; d=google.com; s=arc-20160816; b=PGqgXPQIvIz2UeGuSjqCo0HhXgGe/dEES+fysghnUjBx8pJQK7S3II0fCaiPNXbvYV wCJaTApGlKpOLz8RoiiVbwwLNhBiTC61J51s8PIlI9BzNxMMAff19ZZdxBLT94cUaaha 5nCEUHzKFLmYuuD9xVfkYHBO2ARXbgC07hINbpzsK4f7oKSKoj9vSGfxFVrZOlw5jYri fbiA1BXyoBC4X6RCQ/ZwYk2nfwKOwzf3rFIDrjWC2mGk1mRhorSwejgdnNSWru8NW+5d dlxLoA4+9/9CaBgAa9OyuvHY4V/5xSLWuAPyX1MHi5Jyv0rOd7HpmH0RNK9T1Ns9mHT2 KQLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=biBEh2xyG7QOz0vWY4fM+UdTv5nwnU3LRB3gcCSBxrI=; b=K9IPQNmrNCEE6+IA7lAS1Q3rue4ZXs2VXKZiHSrF8fesQvgy8jQpmEXqtz6ZI29Myc dDzICr0NsF5+LPrahdqwWa6cbPzSqolZ/9+ZCgzpbqySKOr8srRcH2SebuCnuRNogS+f UsmAz6dOfkbXOh82wMoXV6bpH2OkfNMk7M3uYrKJmo1GTUgTk1R6Mru2W0OrojF3ABg4 1+Y29j0Y00r1WOHZT0slIvksL6bV62QVe9PKErdiDBwaOi9nVYbwjOqSHkZd5oYwzgoW ZJCxk9IIfJm/SeGGYecO8AE2oLSTe1IhTZhLKPCAisRvJtWA1D+hqu0ep2ZDX7UZzwyu ghpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ix6qR2sP; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oo21si2920904ejb.453.2020.05.09.07.59.14; Sat, 09 May 2020 07:59:39 -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=@redhat.com header.s=mimecast20190719 header.b=Ix6qR2sP; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728110AbgEIO4i (ORCPT + 99 others); Sat, 9 May 2020 10:56:38 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:45624 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728115AbgEIO4i (ORCPT ); Sat, 9 May 2020 10:56:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589036196; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=biBEh2xyG7QOz0vWY4fM+UdTv5nwnU3LRB3gcCSBxrI=; b=Ix6qR2sPtCcFcyzRvtTh50vlUGA8puaT9k9Xn7Opv4WQc8jA6/aIXEP9OMr2j3BRpdMBS+ 7/d85EqKErBCxuTVbUAfL4+UpzzanLLGt2l+865PEfknnHJ85zGuY1tHRHnIw18DLeUakM lRMy9s3+8P1uq0FvZDJzN7irbhwtFdE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-221-MPQ1STaMOfSNwr8bvkqY-A-1; Sat, 09 May 2020 10:56:32 -0400 X-MC-Unique: MPQ1STaMOfSNwr8bvkqY-A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 08901800D24; Sat, 9 May 2020 14:56:30 +0000 (UTC) Received: from x1-fbsd (unknown [10.3.128.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CA879323; Sat, 9 May 2020 14:56:16 +0000 (UTC) Date: Sat, 9 May 2020 10:56:14 -0400 From: Rafael Aquini To: Luis Chamberlain Cc: Tso Ted , Adrian Bunk , Linus Torvalds , Greg Kroah-Hartman , Laura Abbott , Jeff Mahoney , Jiri Kosina , Jessica Yu , Takashi Iwai , Ann Davis , Richard Palethorpe , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kexec@lists.infradead.org, linux-fsdevel@vger.kernel.org, dyoung@redhat.com, bhe@redhat.com, corbet@lwn.net, keescook@chromium.org, akpm@linux-foundation.org, cai@lca.pw, rdunlap@infradead.org Subject: Re: [PATCH v2] kernel: add panic_on_taint Message-ID: <20200509145614.GA6704@x1-fbsd> References: <20200507180631.308441-1-aquini@redhat.com> <20200507182257.GX11244@42.do-not-panic.com> <20200507184307.GF205881@optiplex-lnx> <20200507184705.GG205881@optiplex-lnx> <20200507203340.GZ11244@42.do-not-panic.com> <20200507220606.GK205881@optiplex-lnx> <20200507222558.GA11244@42.do-not-panic.com> <20200508124719.GB367616@optiplex-lnx> <20200509034854.GI11244@42.do-not-panic.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200509034854.GI11244@42.do-not-panic.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 09, 2020 at 03:48:54AM +0000, Luis Chamberlain wrote: > On Fri, May 08, 2020 at 08:47:19AM -0400, Rafael Aquini wrote: > > On Thu, May 07, 2020 at 10:25:58PM +0000, Luis Chamberlain wrote: > > > On Thu, May 07, 2020 at 06:06:06PM -0400, Rafael Aquini wrote: > > > > On Thu, May 07, 2020 at 08:33:40PM +0000, Luis Chamberlain wrote: > > > > > I *think* that a cmdline route to enable this would likely remove the > > > > > need for the kernel config for this. But even with Vlastimil's work > > > > > merged, I think we'd want yet-another value to enable / disable this > > > > > feature. Do we need yet-another-taint flag to tell us that this feature > > > > > was enabled? > > > > > > > > > > > > > I guess it makes sense to get rid of the sysctl interface for > > > > proc_on_taint, and only keep it as a cmdline option. > > > > > > That would be easier to support and k3eps this simple. > > > > > > > But the real issue seems to be, regardless we go with a cmdline-only option > > > > or not, the ability of proc_taint() to set any arbitrary taint flag > > > > other than just marking the kernel with TAINT_USER. > > > > > > I think we would have no other option but to add a new TAINT flag so > > > that we know that the taint flag was modified by a user. Perhaps just > > > re-using TAINT_USER when proc_taint() would suffice. > > > > > > > We might not need an extra taint flag if, perhaps, we could make these > > two features mutually exclusive. The idea here is that bitmasks added > > via panic_on_taint get filtered out in proc_taint(), so a malicious > > user couldn't exploit the latter interface to easily panic the system, > > when the first one is also in use. > > I get it, however I I can still see the person who enables enabling > panic-on-tain wanting to know if proc_taint() was used. So even if > it was not on their mask, if it was modified that seems like important > information for a bug report analysis. > For that purpose (tracking user taints) I think sth between these lines would work: diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 8a176d8727a3..651a82c13621 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2602,6 +2602,9 @@ int proc_douintvec(struct ctl_table *table, int write, do_proc_douintvec_conv, NULL); } +/* track which taint bits were set by the user */ +static unsigned long user_tainted; + /* * Taint values can only be increased * This means we can safely use a temporary. @@ -2629,11 +2632,20 @@ static int proc_taint(struct ctl_table *table, int write, */ int i; for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) { - if ((tmptaint >> i) & 1) + if ((tmptaint >> i) & 1) { + set_bit(i, &user_tainted); add_taint(i, LOCKDEP_STILL_OK); + } } } + /* + * Users with SYS_ADMIN capability can fiddle with any arbitrary + * taint flag through this interface. + * If that's the case, we also need to mark the kernel "tainted by user" + */ + add_taint(TAINT_USER, LOCKDEP_STILL_OK); + return err; } I don't think, though, it's panic_on_taint work to track that. I posted a v3 for this feature with a way to select if one wants to avoid user forced taints triggering panic() for flags also set for panic_on_taint. Cheers, -- Rafael