Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752119AbdHGGmD (ORCPT ); Mon, 7 Aug 2017 02:42:03 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49629 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752065AbdHGGmC (ORCPT ); Mon, 7 Aug 2017 02:42:02 -0400 From: Chandan Rajendra To: Arnd Bergmann Cc: "Theodore Ts'o" , Andreas Dilger , Kees Cook , Andrew Morton , Jan Kara , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, "Theodore Ts'o" Subject: Re: [PATCH 1/2] ext4: fix warning about stack corruption Date: Mon, 07 Aug 2017 12:12:33 +0530 In-Reply-To: <20170801120438.1582336-1-arnd@arndb.de> References: <20170726185219.GA57833@beast> <20170801120438.1582336-1-arnd@arndb.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-TM-AS-MML: disable x-cbid: 17080706-0040-0000-0000-0000034D01D5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17080706-0041-0000-0000-00000CCA045D Message-Id: <1591040.QxnHWsmrMC@localhost.localdomain> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-08-07_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1708070116 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1814 Lines: 37 On Tuesday, August 1, 2017 5:34:03 PM IST Arnd Bergmann wrote: > After commit 62d1034f53e3 ("fortify: use WARN instead of BUG for now"), > we get a warning about possible stack overflow from a memcpy that > was not strictly bounded to the size of the local variable: > > inlined from 'ext4_mb_seq_groups_show' at fs/ext4/mballoc.c:2322:2: > include/linux/string.h:309:9: error: '__builtin_memcpy': writing between 161 and 1116 bytes into a region of size 160 overflows the destination [-Werror=stringop-overflow=] > > We actually had a bug here that would have been found by the warning, > but it was already fixed last year in commit 30a9d7afe70e ("ext4: fix > stack memory corruption with 64k block size"). > > This replaces the fixed-length structure on the stack with a variable-length > structure, using the correct upper bound that tells the compiler that > everything is really fine here. I also change the loop count to check > for the same upper bound for consistency, but the existing code is > already correct here. > > Note that while clang won't allow certain kinds of variable-length arrays > in structures, this particular instance is fine, as the array is at the > end of the structure, and the size is strictly bounded. > > There is one remaining issue with the function that I'm not addressing > here: With s_blocksize_bits==16, we don't actually print the last two > members of the array, as we loop though just the first 14 members. > This could be easily addressed by adding two extra columns in the output, > but that could in theory break parsers in user space, and should be > a separate patch if we decide to modify it. > I executed xfstests on a ppc64 machine with both 4k and 64k block size combination. Tested-by: Chandan Rajendra -- chandan