Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp880534pxk; Thu, 17 Sep 2020 20:11:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO/O5yVXt9mL5CTMNmyJmEF7zoNeR/KOOyD53egxOp8Va8ZJNb9sTBl+nRjqP/wVDcXybr X-Received: by 2002:a17:907:213b:: with SMTP id qo27mr33018230ejb.441.1600398696970; Thu, 17 Sep 2020 20:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398696; cv=none; d=google.com; s=arc-20160816; b=ptSLo6ZalRzMBa0Qm06z4MgeMN1llKaAcwMSUob2ueubwjxiLx9raDq4eZ8BfbyMga L1+YAD4jBTDOXwsU+J75CnUQ4VSakCtz76PWP1mLL+u5iWWiq2/1CkdrgSDeZPY4jKBZ kgbHWFDoberkiGwHg8t5VWwtGAoAj4u2EzfJEB543vy2nrMPGxqUOB9seSQjPDda2dha UNbnYQ/frQsn23A+tvqRADjkwDphXwYHkQKt//gYVPJiTA4XR3VuA7Dn11qo0ccw4A2F 2uv0mr3bfS8Ha4dsy8tyjkzSOZkVJXGNJJIk6FKXcQpYWp7LqhCDfxdXePXB95O2gYqG ku2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0XzcUpmEChgHs/aMJPtunl5YWFOBG/TL/8ns+XzjEU8=; b=zXzWz3pT58hKoFvdCvbuthb/3m115K7FsJvS4lH92GSQuiu2l6wC/e6/8E3cQ6M03u teSUYQrgWCFGAmAVGcNN8gyeFhVLzDmCFpHAdy6TvHWW+5qUrNWpj7b9GKrbPAbUyRbv t/sQQOQnHHsFQET2UEZkrJhLwXpYX4wqyOHzeRAT8faBNQ4JZi0pLfPchSFzjGrtqUi+ Kag/wRAJrDFEPna48HMuQCfvu975JQvP2k6XGJ5+mKhMZzXZLUzt5+l3QJgKsjySvnKl yUGj6ObQJB2qR1M7MYv6/qW8Hb7LyJhtjh7/82Wec6J56ZwiVBXFbIwM39xZYyr3iyTE aFig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VzHLpXd+; 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 v26si1187949ejr.748.2020.09.17.20.11.13; Thu, 17 Sep 2020 20:11:36 -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=VzHLpXd+; 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 S1730637AbgIRDHw (ORCPT + 99 others); Thu, 17 Sep 2020 23:07:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:50184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbgIRCDk (ORCPT ); Thu, 17 Sep 2020 22:03:40 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 8B10E208DB; Fri, 18 Sep 2020 02:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394619; bh=f0+XAjM5+5/LhxBHnBVlXukbbef4qgWjJksQ0qln4Fs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VzHLpXd+dfRZHx5lf666/Lw78cB9+6MmPOdAlxUdcKedp+UdErp5/VXocHj6lwA4b YFSniNRCYLtEbQuQbRZGoCZ017OmOURhlfwtprpCP2syBzmJ63OgRf9KugewFZvUdM zOkjbiELWmuOKJihHU9xiDIVuKJMe1VJ4l4lhdfc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vasily Averin , Stephen Smalley , Paul Moore , Sasha Levin , selinux@tycho.nsa.gov, linux-security-module@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 121/330] selinux: sel_avc_get_stat_idx should increase position index Date: Thu, 17 Sep 2020 21:57:41 -0400 Message-Id: <20200918020110.2063155-121-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vasily Averin [ Upstream commit 8d269a8e2a8f0bca89022f4ec98de460acb90365 ] If seq_file .next function does not change position index, read after some lseek can generate unexpected output. $ dd if=/sys/fs/selinux/avc/cache_stats # usual output lookups hits misses allocations reclaims frees 817223 810034 7189 7189 6992 7037 1934894 1926896 7998 7998 7632 7683 1322812 1317176 5636 5636 5456 5507 1560571 1551548 9023 9023 9056 9115 0+1 records in 0+1 records out 189 bytes copied, 5,1564e-05 s, 3,7 MB/s $# read after lseek to midle of last line $ dd if=/sys/fs/selinux/avc/cache_stats bs=180 skip=1 dd: /sys/fs/selinux/avc/cache_stats: cannot skip to specified offset 056 9115 <<<< end of last line 1560571 1551548 9023 9023 9056 9115 <<< whole last line once again 0+1 records in 0+1 records out 45 bytes copied, 8,7221e-05 s, 516 kB/s $# read after lseek beyond end of of file $ dd if=/sys/fs/selinux/avc/cache_stats bs=1000 skip=1 dd: /sys/fs/selinux/avc/cache_stats: cannot skip to specified offset 1560571 1551548 9023 9023 9056 9115 <<<< generates whole last line 0+1 records in 0+1 records out 36 bytes copied, 9,0934e-05 s, 396 kB/s https://bugzilla.kernel.org/show_bug.cgi?id=206283 Signed-off-by: Vasily Averin Acked-by: Stephen Smalley Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- security/selinux/selinuxfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index e6c7643c3fc08..e9eaff90cbccd 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -1508,6 +1508,7 @@ static struct avc_cache_stats *sel_avc_get_stat_idx(loff_t *idx) *idx = cpu + 1; return &per_cpu(avc_cache_stats, cpu); } + (*idx)++; return NULL; } -- 2.25.1