From patchwork Fri Aug 23 07:22:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eryu Guan X-Patchwork-Id: 11110789 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD04E112C for ; Fri, 23 Aug 2019 07:24:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C47D822CEC for ; Fri, 23 Aug 2019 07:24:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731583AbfHWHYP (ORCPT ); Fri, 23 Aug 2019 03:24:15 -0400 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:60570 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731070AbfHWHYP (ORCPT ); Fri, 23 Aug 2019 03:24:15 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R731e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=eguan@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0TaC4p6A_1566545050; Received: from localhost(mailfrom:eguan@linux.alibaba.com fp:SMTPD_---0TaC4p6A_1566545050) by smtp.aliyun-inc.com(127.0.0.1); Fri, 23 Aug 2019 15:24:10 +0800 From: Eryu Guan To: fstests@vger.kernel.org Cc: "Darrick J. Wong" , Eryu Guan Subject: [PATCH] ltp/fsx: avoid infinite loop while finding offset2 in clone/dedupe/copy range ops Date: Fri, 23 Aug 2019 15:22:59 +0800 Message-Id: <20190823072259.56671-1-eguan@linux.alibaba.com> X-Mailer: git-send-email 2.14.4.44.g2045bb6 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org In CLONE/DEDUPE/COPY RANGE operations, we pick a "offset" and "size" first, then find a suitable "offset2" by looping if there's overlap (|offset2-offset| < size) or final file size is greater than max file size (offset2 + size > maxfilelen). But it's possible that there's no such suitable offset2 and we loop forever. e.g. block_size = 4096, offset = 0, size = 4096 and maxfilelen is a value smaller than 8212 (which could be set via '-l' option). Fix it by making sure maxfilelen/file_size is big enough to hold 'size' bytes from 'offset2', and just skip this operation if not. Signed-off-by: Eryu Guan --- ltp/fsx.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ltp/fsx.c b/ltp/fsx.c index 06d08e4e93f3..f6eb3308e8bc 100644 --- a/ltp/fsx.c +++ b/ltp/fsx.c @@ -1825,6 +1825,14 @@ do { \ TRIM_LEN(off, len, size); \ } while (0) +#define CHECK_RANGE(off, len, size) \ +do { \ + if ((off + len * 2) > size) { \ + log5(op, offset, size, -1, FL_SKIPPED); \ + goto out; \ + } \ +} while (0) + void cleanup(int sig) { @@ -1989,6 +1997,7 @@ test(void) TRIM_OFF_LEN(offset, size, file_size); offset = offset & ~(block_size - 1); size = size & ~(block_size - 1); + CHECK_RANGE(offset, size, maxfilelen); do { offset2 = random(); TRIM_OFF(offset2, maxfilelen); @@ -2003,6 +2012,7 @@ test(void) TRIM_OFF_LEN(offset, size, file_size); offset = offset & ~(block_size - 1); size = size & ~(block_size - 1); + CHECK_RANGE(offset, size, file_size); do { if (tries++ >= 30) { size = 0; @@ -2020,6 +2030,7 @@ test(void) offset -= offset % readbdy; if (o_direct) size -= size % readbdy; + CHECK_RANGE(offset, size, maxfilelen); do { offset2 = random(); TRIM_OFF(offset2, maxfilelen);