From nobody Wed Nov 27 12:32:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699284818; cv=none; d=zohomail.com; s=zohoarc; b=av2rSe1C9UJK1QsMCY3VFCibfieyBw+ziREdxHsr6YQameFOJnSsX6dvbCzWN0S/gepU2qqFll/I866ggAwClm3tjRtD5NkkqlcHIDcxDKizTGtBJEQdGMCN5pUeg/XiCUEJ2ZqkwCYwc93S0yrpZwPxTZyghpytBNu/Pq8Bh+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699284818; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=8uZpTC7vfc/gISeKzm+ZO3nrKEzBmGcZTgy+gByZUp0=; b=fLoHYUILNtpf5rAZ/Ip1+Onniev/hB7N7bFlqbqzpjCRGQZkNJrwLAwJNdViR9zAPLhEeFuU/VDk38dEZbi/FpI8p56s6rdoosBOntoAmXMJgYxao8sf27UJWqruPV5LDLWDbvcWrl8598KveAiWQuC/FQnr+GjR5IUSeVpkb0Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699284818525331.4899789623911; Mon, 6 Nov 2023 07:33:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r01b9-00008K-Q9; Mon, 06 Nov 2023 10:33:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r01au-000806-Lx for qemu-devel@nongnu.org; Mon, 06 Nov 2023 10:32:54 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r01am-0004Nq-OZ for qemu-devel@nongnu.org; Mon, 06 Nov 2023 10:32:51 -0500 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-32fb1d757f7so2447227f8f.0 for ; Mon, 06 Nov 2023 07:32:43 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id d5-20020adff2c5000000b0032da6f17ffdsm9752176wrp.38.2023.11.06.07.32.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 07:32:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699284762; x=1699889562; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=8uZpTC7vfc/gISeKzm+ZO3nrKEzBmGcZTgy+gByZUp0=; b=n9sgcm9Q8AF5M/oZgvhLD7tm10iFvKv6sg6Ug5Wp4BNBockuiuUgCx/y3mkg3rvih4 TAhCQFD2eJzoreyXq6kxpYLWSZ7t21OiU8v/hd2qIxN/6+HfbuYYK1anyocUa4AwHIhk x1j6AVjN2nd4/z9T48493N1vZBaSLPfuukN33mDoxz7MkDjnK+Oe4lSZtjqCQ57OuTCd Yvzb7iXLcJ//IFRaT1yXbC7akmWeoQn8hLWJc5YofhBn37KEGX2yVda8yD2gfakoy671 iOpyFhvhxHMPQgZc9cKLJiH8a5LkD8UQn+FIr82LscesZv1sUQzOmPzYsavVCxowO5Q1 o6ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699284762; x=1699889562; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8uZpTC7vfc/gISeKzm+ZO3nrKEzBmGcZTgy+gByZUp0=; b=E3cy9ojxlfa5g2S16yecUs/Ix0PL/9ddsCN6bafTpVpVSTh/nXeTgm6rPNjWGn5a3M b3Fv9lDyX0tEYWCrl4eNP+tpf98Kixoa83ybLc2UpeRaFEWOmOuHZb0A4D8EILO91Xgl pCJVlNAMh1in6pHADUfTrIJwaI0JNCyXxYS3fLDfisVz3c+iacWGO11gSke7e0ahXaYF 6VJ3FcdKnk/sRJ0YP5rU8/T+TidK86mgRXTmpgGv0nbPnXNCgk+M9BrIMt2Tu7zxFCEL VFF766qUvSCOmmGmV+m6AtpGewzoHwDoKpB0FB9wx4u6fMTaByRVpYaS9hmGXoIAFeF7 1fWw== X-Gm-Message-State: AOJu0Yxcb6D1a3wcdsru67kCnKSqN5MWP3QwqzNpzA1W3Ps/dVFikdCr EI1EsA8ud3e5l/DPfTwmItUSM1f9wlCtjLDQ30Q= X-Google-Smtp-Source: AGHT+IE0cKtfN7n8+wxzdMUTKzm/QvBbraAz9Vd2iI6Y8cs4n40hF20jVCdDHMtoJ6vqocoW+YDZcw== X-Received: by 2002:adf:ef02:0:b0:323:1887:dd6d with SMTP id e2-20020adfef02000000b003231887dd6dmr26338138wro.3.1699284762205; Mon, 06 Nov 2023 07:32:42 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 06/12] util/filemonitor-inotify: qemu_file_monitor_watch(): assert no overflow Date: Mon, 6 Nov 2023 15:32:32 +0000 Message-Id: <20231106153238.1426649-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106153238.1426649-1-peter.maydell@linaro.org> References: <20231106153238.1426649-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699284821069100007 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Prefer clear assertions instead of [im]possible array overflow. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Peter Maydell Reviewed-by: Maksim Davydov Message-id: 20231017125941.810461-3-vsementsov@yandex-team.ru Signed-off-by: Peter Maydell --- util/filemonitor-inotify.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/util/filemonitor-inotify.c b/util/filemonitor-inotify.c index 2c45f7f1764..2121111f38b 100644 --- a/util/filemonitor-inotify.c +++ b/util/filemonitor-inotify.c @@ -81,16 +81,25 @@ static void qemu_file_monitor_watch(void *arg) =20 /* Loop over all events in the buffer */ while (used < len) { - struct inotify_event *ev =3D - (struct inotify_event *)(buf + used); - const char *name =3D ev->len ? ev->name : ""; - QFileMonitorDir *dir =3D g_hash_table_lookup(mon->idmap, - GINT_TO_POINTER(ev->wd)= ); - uint32_t iev =3D ev->mask & - (IN_CREATE | IN_MODIFY | IN_DELETE | IN_IGNORED | - IN_MOVED_TO | IN_MOVED_FROM | IN_ATTRIB); + const char *name; + QFileMonitorDir *dir; + uint32_t iev; int qev; gsize i; + struct inotify_event *ev =3D (struct inotify_event *)(buf + used); + + /* + * We trust the kenel to provide valid buffer with complete event + * records. + */ + assert(len - used >=3D sizeof(struct inotify_event)); + assert(len - used - sizeof(struct inotify_event) >=3D ev->len); + + name =3D ev->len ? ev->name : ""; + dir =3D g_hash_table_lookup(mon->idmap, GINT_TO_POINTER(ev->wd)); + iev =3D ev->mask & + (IN_CREATE | IN_MODIFY | IN_DELETE | IN_IGNORED | + IN_MOVED_TO | IN_MOVED_FROM | IN_ATTRIB); =20 used +=3D sizeof(struct inotify_event) + ev->len; =20 --=20 2.34.1