From patchwork Mon Mar 22 16:02:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 406161 Delivered-To: patch@linaro.org Received: by 2002:a17:906:5290:0:0:0:0 with SMTP id c16csp1347516ejm; Mon, 22 Mar 2021 09:04:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2qLO+0fqABYy6u1yqRtBh2mcJbOoQpNENlLWcoDTA4P5o/z8KP1YycJaIdfJAQkKrdvi3 X-Received: by 2002:a62:800c:0:b029:203:6990:78e2 with SMTP id j12-20020a62800c0000b0290203699078e2mr528438pfd.3.1616429068106; Mon, 22 Mar 2021 09:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616429068; cv=none; d=google.com; s=arc-20160816; b=C8vzvtGPMum7D7EW0wf4QeEq2P1R15ThsKggQ8h/tFicqY+UA4rAg33aGgZrXLIAzU HOViKPY/5Um418Vbl1uFRnauoQUOfn5MkOG/FR7s9zWl3NvzKVrsB8GLORKhUrSfbFVu sDIVFOCapnv5X5x+tdWH5BkEcwI/fQN6id29wyg+HMRAKlJFF1fZ2NeozUHeKwyKqNth Kt8SYD/QqJ9621D7nONTUBVSmG7L8gbDjatgTzNtG5hamzxaw/s9qiCByDariBgCFof8 jmsJ6Zo5lTJu4SaKTz3yP4W5rqyCgoaXxnM7DgCL4PM0xYzFE6BLBY7uY12PGsyxXo9X sQpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:delivered-to; bh=xKsCPQYCwaCSczjEvOM5OqW9KxGmGPabdyMU3aSnopE=; b=ZUfrIn2Hl4CAfrrhGB7+RChEwMRmxcGp5bPDXkjaPhlXhe/m5VMhXojfPLceixpbvW Ht+Z4bdXD8eYw/byiHd/dRGDDBp0LGdmIRYlzQFx1cGKReEUpyFttZvx4uE525zHgZeF fhYvYVwLF29ygAy2UaX5UySQoFBjOXPbelzDo79nHEJS/wnsoBaCDqnPMwXu+DdHbIIR Zmt/0sbqkNMoTiTj+u72oJnzsrV+OXU6wDihyP8NrEI1mw7v21EotV0yQXFiWVKVsW5I NRU1O3a9TI3NM3G3ZKmZkmb9NFBJu/bvmoKiHZ9EEgWxVaElxsmHTXotJx1XTLlJLTtL mZkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=MU4IL9JN; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id y21si13924111pgj.546.2021.03.22.09.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 09:04:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=MU4IL9JN; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1BC336E4FE; Mon, 22 Mar 2021 16:04:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by gabe.freedesktop.org (Postfix) with ESMTPS id 201256E4FE; Mon, 22 Mar 2021 16:04:26 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id D63E5619A4; Mon, 22 Mar 2021 16:04:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616429066; bh=nkpO3F9iV2LP9C5b1X1yN1ZVysmYmotRTLuBUWIaptM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MU4IL9JNNK+J8U+vvpLpwovR+/suU+W9R4RhhhMaub4p/qt1HSm7/5H/LxJjfRA1v f+dccndcC0t+6DndIOBCJbVJvgtAFbUO/Xj+Ad4PAK3HRVGVN0VmdJVzwNG2nWP60W yoMi7GzhcMMul2Me0RQEOrAkh9+ikItIp0T7LrmMn4UxhxHfYhCqAAaad++VD478Ly WRurbxWp7EoqaQbB5aDSFB4iZyCpOkFivtOdus8BKdINgwMELaIsTcoM1dTXGsBCvO NUlZI47cRIaTlBnQpp36y5LIoHJRasVTH3KqfKgtuhF/A3Vph299qnut15q3EDnfE2 ATElHLu2Uchbw== From: Arnd Bergmann To: linux-kernel@vger.kernel.org, Martin Sebor , Anders Larsen Subject: [PATCH 05/11] qnx: avoid -Wstringop-overread warning Date: Mon, 22 Mar 2021 17:02:43 +0100 Message-Id: <20210322160253.4032422-6-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210322160253.4032422-1-arnd@kernel.org> References: <20210322160253.4032422-1-arnd@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-security-module@vger.kernel.org, dri-devel@lists.freedesktop.org, Arnd Bergmann , netdev@vger.kernel.org, "James E.J. Bottomley" , x86@kernel.org, linux-wireless@vger.kernel.org, James Smart , ath11k@lists.infradead.org, Ning Sun , tboot-devel@lists.sourceforge.net, linux-arm-kernel@lists.infradead.org, cgroups@vger.kernel.org, linux-scsi@vger.kernel.org, Tejun Heo , Simon Kelley , intel-gfx@lists.freedesktop.org, Kalle Valo , Serge Hallyn Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Arnd Bergmann gcc-11 warns that the size of the link name is longer than the di_fname field: fs/qnx4/dir.c: In function ‘qnx4_readdir’: fs/qnx4/dir.c:51:32: error: ‘strnlen’ specified bound 48 exceeds source size 16 [-Werror=stringop-overread] 51 | size = strnlen(de->di_fname, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from fs/qnx4/qnx4.h:3, from fs/qnx4/dir.c:16: include/uapi/linux/qnx4_fs.h:45:25: note: source object declared here 45 | char di_fname[QNX4_SHORT_NAME_MAX]; The problem here is that we access the same pointer using two different structure layouts, but gcc determines the object size based on whatever it encounters first. Change the strnlen to use the correct field size in each case, and change the first access to be on the longer field. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578 Signed-off-by: Arnd Bergmann --- fs/qnx4/dir.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/qnx4/dir.c b/fs/qnx4/dir.c index a6ee23aadd28..68046450e543 100644 --- a/fs/qnx4/dir.c +++ b/fs/qnx4/dir.c @@ -39,21 +39,20 @@ static int qnx4_readdir(struct file *file, struct dir_context *ctx) ix = (ctx->pos >> QNX4_DIR_ENTRY_SIZE_BITS) % QNX4_INODES_PER_BLOCK; for (; ix < QNX4_INODES_PER_BLOCK; ix++, ctx->pos += QNX4_DIR_ENTRY_SIZE) { offset = ix * QNX4_DIR_ENTRY_SIZE; - de = (struct qnx4_inode_entry *) (bh->b_data + offset); - if (!de->di_fname[0]) + le = (struct qnx4_link_info *)(bh->b_data + offset); + de = (struct qnx4_inode_entry *)(bh->b_data + offset); + if (!le->dl_fname[0]) continue; if (!(de->di_status & (QNX4_FILE_USED|QNX4_FILE_LINK))) continue; if (!(de->di_status & QNX4_FILE_LINK)) - size = QNX4_SHORT_NAME_MAX; + size = strnlen(de->di_fname, sizeof(de->di_fname)); else - size = QNX4_NAME_MAX; - size = strnlen(de->di_fname, size); + size = strnlen(le->dl_fname, sizeof(le->dl_fname)); QNX4DEBUG((KERN_INFO "qnx4_readdir:%.*s\n", size, de->di_fname)); if (!(de->di_status & QNX4_FILE_LINK)) ino = blknum * QNX4_INODES_PER_BLOCK + ix - 1; else { - le = (struct qnx4_link_info*)de; ino = ( le32_to_cpu(le->dl_inode_blk) - 1 ) * QNX4_INODES_PER_BLOCK + le->dl_inode_ndx;