Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp70620ybk; Tue, 12 May 2020 15:41:49 -0700 (PDT) X-Google-Smtp-Source: APiQypKgA3zxlkI7X9KIX5wwjvCAUzmMj/upV9CHzNH8FIF/yNioV1idvq4LGK/xRuLEIRMsuQk4 X-Received: by 2002:a50:a624:: with SMTP id d33mr20391317edc.58.1589323308928; Tue, 12 May 2020 15:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589323308; cv=none; d=google.com; s=arc-20160816; b=X9yrsjCSG9cRU3KF4KfDZ7RNMPEYojWmRiW+LIIOkbkkPKrqGqDFZm0oWv0E35HccS ongigK8yuZn2WU5Cv0LO/DPJ31dhqsCxhjO/1DV9ONbe2erHxDhsjPOJLewpbYNl8O+r 1LsQHg/kEDX1iPkIDO47+UW4UtxIg5M1dpAzeWUarplXA79nNbnrrcQRRRTzAKMMDZpt 6sh9gDyJWgQK/vF1s6pdH4rGgLhzJ+Nb3B4MbUHvxgTI3hfmUWkOBL642Y7Ih7yGx7J5 XTnu7UB7JEwhCJ7g+nox5cg5DBDM1et5whrHByRolIjnDY5y2wWrZZiCzbY11vhebqsU gxjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Gn7nXTm0O1XhEm5zfYkiFb/JrISIuLYstdkDlREWsE8=; b=cIPnbt4xMOMfCOVS/gakMdrQ4wL+OJEk7I8sVqerl3yw7UEEoqgMYq0yldHROLa2RV EnldVkd29V2U2KOPDHW3LD3tGbh3Z3st0wGK36WSCX1Rs+pL1Z8OLB8TvlIjnfRL4uiG RCx1zBSyXIauh2Gv9NDRrPYYLpMOgCCkIWGGnWXEofRTciHZi0INJDF6f20+mYUkU7mA ZamIVnj9RTUs0jPtdPVgccxGedZqtR9ea6UBbTJPbZJdg3OlCQJEYswUbiZnsm+XDXVx nj10vdXn5LbnVWcl4Eik3lO/HPZ29Ql9epwRFriKdR9kv0PWixFUebPXZqYWw78OK7j2 HQgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BLjhGhUV; 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 13si8389687ejz.499.2020.05.12.15.41.26; Tue, 12 May 2020 15:41:48 -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=BLjhGhUV; 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 S1728314AbgELWj5 (ORCPT + 99 others); Tue, 12 May 2020 18:39:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:29720 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726031AbgELWj5 (ORCPT ); Tue, 12 May 2020 18:39:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589323196; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Gn7nXTm0O1XhEm5zfYkiFb/JrISIuLYstdkDlREWsE8=; b=BLjhGhUVBS6MkMdM0L3ydl7Zzh/sJUTyOW/mn5U8My93PubPWPY08UhJUL46oK95tIzUpO MgoekkOsjMgcPJZpPPUMKIMRSkhapUb5arJqNXWR7y84B7anF301zX8pcoEbaotXMEbAoJ sdhEIv52UpQzC+WbcSsPBRipxjpPVCw= 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-217-k72NQ3s4Pdut49pbsVXbkw-1; Tue, 12 May 2020 18:39:52 -0400 X-MC-Unique: k72NQ3s4Pdut49pbsVXbkw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 02ED3800687; Tue, 12 May 2020 22:39:51 +0000 (UTC) Received: from optiplex-lnx.redhat.com (unknown [10.3.128.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D6B6648D7; Tue, 12 May 2020 22:39:49 +0000 (UTC) From: Rafael Aquini To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, mcgrof@kernel.org Cc: keescook@chromium.org, akpm@linux-foundation.org, yzaikin@google.com, tytso@mit.edu Subject: [PATCH v2] kernel: sysctl: ignore out-of-range taint bits introduced via kernel.tainted Date: Tue, 12 May 2020 18:39:46 -0400 Message-Id: <20200512223946.888020-1-aquini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Users with SYS_ADMIN capability can add arbitrary taint flags to the running kernel by writing to /proc/sys/kernel/tainted or issuing the command 'sysctl -w kernel.tainted=...'. These interface, however, are open for any integer value and this might an invalid set of flags being committed to the tainted_mask bitset. This patch introduces a simple way for proc_taint() to ignore any eventual invalid bit coming from the user input before committing those bits to the kernel tainted_mask. Signed-off-by: Rafael Aquini --- Changelog: v2: simplify the bit iterator within proc_taint(), and silently drop out-of-range bits (akpm) kernel/sysctl.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 8a176d8727a3..fcd46fc41206 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2628,10 +2628,9 @@ static int proc_taint(struct ctl_table *table, int write, * to everyone's atomic.h for this */ int i; - for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) { - if ((tmptaint >> i) & 1) + for (i = 0; i < TAINT_FLAGS_COUNT; i++) + if ((1UL << i) & tmptaint) add_taint(i, LOCKDEP_STILL_OK); - } } return err; -- 2.25.4