From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41C8AC43464 for ; Fri, 18 Sep 2020 02:17:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE0902396D for ; Fri, 18 Sep 2020 02:17:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600395453; bh=VdfvPI2L/8LAtm8y6SS7utxBrVk3AbiPhArVErrYgOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=D2kpxzjjYFOb5GZPZ/4Rc5NsjiHId/dw01C/rISr+53XASRedHFvaGy5XvVtKFLqM 8Isw0cHxuU9qiXggQTKTsO8GlQ24PvBQsvJXVCINHEwMeZtaOPUCXZv91B0eciNn82 YtbFU5bH4hwHJUcDRO3ab8c9rVbuWhbmtz4a5CQk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729543AbgIRCRa (ORCPT ); Thu, 17 Sep 2020 22:17:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:47708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729177AbgIRCRP (ORCPT ); Thu, 17 Sep 2020 22:17:15 -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 24EFD238A0; Fri, 18 Sep 2020 02:17:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600395435; bh=VdfvPI2L/8LAtm8y6SS7utxBrVk3AbiPhArVErrYgOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OWrVXKEDTm+O4FpGXpolkXrKaNdDXrhrlrMHa0mJ9KbzACSd1s8UCEQFibcbakhVT mrvpNP2d8L67AUOrhY7hEj27s9qwIHnJyWqdb2+t3u49iByYG0x1vMNjfDiEMwnkgK CkhwgPwWT7HB6Gs77Nm7O/xPcRWEUEe0LwhEziTI= 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 4.4 25/64] selinux: sel_avc_get_stat_idx should increase position index Date: Thu, 17 Sep 2020 22:16:04 -0400 Message-Id: <20200918021643.2067895-25-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918021643.2067895-1-sashal@kernel.org> References: <20200918021643.2067895-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 c02da25d7b631..7778e28cce9d7 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -1370,6 +1370,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