From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Xq66qUHC; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id A0EF65A004F for ; Tue, 03 Sep 2024 21:25:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725391554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MN2NT3SS0HXMQSnFGXk8VeodAyyD7BL9miyyvHcVtKM=; b=Xq66qUHCtcBrGyGZcNgUrGOZDe/b1vCjTZNJs+mILd3HsLPnohaqt4hQfQJpw7OetkuyIf QoHdLFbtSWzZlAOmCivpUZpVUxsF0QT9xHeeZs2b5nbrQOOIv67BsGOdZGZOEcZljzDttF EIQqbEXTL/QmUZzV+H9zUm5kkrRVjLM= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-401-bvFoFU1SOxqSrWWe1HM16w-1; Tue, 03 Sep 2024 15:25:52 -0400 X-MC-Unique: bvFoFU1SOxqSrWWe1HM16w-1 Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-71440a7cd08so5207300b3a.2 for ; Tue, 03 Sep 2024 12:25:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725391551; x=1725996351; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=MN2NT3SS0HXMQSnFGXk8VeodAyyD7BL9miyyvHcVtKM=; b=fNZLKdfc54/Mgv5QMeTtFvlR9DQqQnCj7NHXvEj/C2wlTLNDZjzbqLpBOn6asffQiw Ga2eBo2KUmtOJ/bVUP51HE/NNgZnf4WER95wz2MQd8O+pG7dzkl2jhz2MQwWBBHiJqX+ BVwDx2gfZHcmNNMCI2SDLQytdOc0Y1iPQoTRQZvBG7xzgkHdfO1QkaxzmyzwIU04hH9Y 6dbSrD5ARIlyhOBZD6DfsriIHGjO4/EAFKHx3dgG/KDWq3Lli2Vi3kmBfyKMlO3fkd9y 7CydcS/1skvGexKZGx5Kde4lFNQ4MTeyJsNY6EQhy1gxgsCBiq/iBs+LNM2CSrRlYvz8 sRkw== X-Gm-Message-State: AOJu0YzrhA3dX9xGYM5MDmJNHIrQV1ycTIR//5k53LfffkLia+MOZ1NK mkRl3xxTi6T81928ZQYnNpWDO2KGJGXx7YTpvWCIFwB++gP6wREZZVZ8lGve8TMktqgPD3O32M7 L4NNj8TWBWqvRdmPbdBlHrtzsbsfP1jyEJR7ypt6WKO4v7JzhsTfcjpdVAw== X-Received: by 2002:a05:6a20:c6ca:b0:1c6:cb01:db61 with SMTP id adf61e73a8af0-1ced62a2caamr11914567637.28.1725391551341; Tue, 03 Sep 2024 12:25:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2LDr3InTdhLNvilV/YL8zWo9qbCD1qlbMuAA1VoZPdCnhk+r/6o0KJwhpvDFixUlFU8lpeA== X-Received: by 2002:a05:6a20:c6ca:b0:1c6:cb01:db61 with SMTP id adf61e73a8af0-1ced62a2caamr11914550637.28.1725391551016; Tue, 03 Sep 2024 12:25:51 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-717785331cfsm231729b3a.77.2024.09.03.12.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 12:25:49 -0700 (PDT) Date: Tue, 3 Sep 2024 21:25:46 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 4/6] tap: Don't risk truncating frames on full buffer in tap_pasta_input() Message-ID: <20240903212546.144bae19@elisabeth> In-Reply-To: <20240903120235.1688429-5-david@gibson.dropbear.id.au> References: <20240903120235.1688429-1-david@gibson.dropbear.id.au> <20240903120235.1688429-5-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 7BE3ECYUA7KRJA7P3FCAK2R3NUCROUJJ X-Message-ID-Hash: 7BE3ECYUA7KRJA7P3FCAK2R3NUCROUJJ X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, 3 Sep 2024 22:02:33 +1000 David Gibson wrote: > tap_pasta_input() keeps reading frames from the tap device until the > buffer is full. However, this has an ugly edge case, when we get close > to buffer full, we will provide just the remaining space as a read() > buffer. If this is shorter than the next frame to read, the tap device > will truncate the frame and discard the remainder. > > Adjust the code to make sure we always have room for a maximum size frame. > > Signed-off-by: David Gibson > --- > tap.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tap.c b/tap.c > index 71742748..2fbcef04 100644 > --- a/tap.c > +++ b/tap.c > @@ -1076,8 +1076,8 @@ static void tap_pasta_input(struct ctx *c, const struct timespec *now) > > tap_flush_pools(); > > - for (n = 0; n < (ssize_t)TAP_BUF_BYTES; n += len) { > - len = read(c->fd_tap, pkt_buf + n, TAP_BUF_BYTES - n); > + for (n = 0; n < (ssize_t)TAP_BUF_BYTES - ETH_MAX_MTU; n += len) { Logically speaking, this should be TAP_BUF_BYTES - ETH_MAX_MTU + 1, I guess, because if we have ETH_MAX_MTU bytes left, we can read another frame. Only if we have strictly less than that we might truncate one. In any case, not a strong preference, and perhaps this version is actually more readable. > + len = read(c->fd_tap, pkt_buf + n, ETH_MAX_MTU); > > if (len <= 0) { > if (errno == EINTR) { -- Stefano