From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00F37C433B4 for ; Mon, 12 Apr 2021 10:49:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 45D7961249 for ; Mon, 12 Apr 2021 10:49:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 45D7961249 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVu7o-0008FK-5G for qemu-devel@archiver.kernel.org; Mon, 12 Apr 2021 06:49:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVu6m-0007g7-5w for qemu-devel@nongnu.org; Mon, 12 Apr 2021 06:47:56 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:56078) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lVu6k-0001Qc-EX for qemu-devel@nongnu.org; Mon, 12 Apr 2021 06:47:55 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 12so6510754wmf.5 for ; Mon, 12 Apr 2021 03:47:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=g7BGOBbLxdqBvtWGkeEHeuFRGYY77sBPkKc6YIDNHrE=; b=DkV3xb7SRM9AQLSUcG3Ehgos/sTx3DyAdfieRn5kf5tqOa0QPvE/oIKiqQzmN4L4/x oDJz4vAEONQLyW5tLN2EVMv6XqzwKWe/jdD2KZoKEu5tB5fPHGZwgfa4rTedycY/nM7w 5AOwxBrivKnL+5dNoS/trELEdk/vmQ1C50q7iLUjfyxDvq3WgBqZ/VYqaAzM/LVsxij/ xv2psrYNmt5zFIB+0SsY0OMqxavDfZ3czAgaXrSdtBM6DPH0vuf/FP1o4A6qYPS+gt5D V4dbjox9ljiLKG4iU9Ti9YT7XIkznhX5WhRi6jZ7YDK8jNsTC6HMQpGWxMuY7jfownCQ vIfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=g7BGOBbLxdqBvtWGkeEHeuFRGYY77sBPkKc6YIDNHrE=; b=JucTsjUmq66ILmN0qu27cdiUsZFtEBjX/trq4vLZZzhL54lubfLnqhgsIcuZSGV10v z/SotnCZ2xjPo1QfnMT6btYd5uiSZRIQgmlCPazh5Sc4dmDHrplrQV6Z33qAq6X7m37q KqjBmyROm9jLBEu0ykOAaEU9Y076NV5gUOluBn2fy0u6nU9D83+UkRAT4Pled1F4om49 J3QBHFPe2soENGGUFEgQljb4xCKlJyghboFDNWIHkNyvBYfnb2HWZ5ijEtH0ZfdHL+eO ZSjNTpweeqO0M/oAjd78kIQYk7ZV8sd+z5eWY2UtQgmPLvP0JEMB2G27azgbUEagbuIR 2asw== X-Gm-Message-State: AOAM530X6txFonZYnERUV0JOWuIvfH0dl0czTxNTEqEcxZTDaD/VLTmd ANjEZq6s3tIdkVLv2RH1Axw= X-Google-Smtp-Source: ABdhPJxgK0zAlRLWfpOCluTyqaoLTFifDLaMvRp2oLcAohNGO9y2mi0Q5UVi3yxpdMFduzLOH4xykg== X-Received: by 2002:a7b:c098:: with SMTP id r24mr5994526wmh.179.1618224473020; Mon, 12 Apr 2021 03:47:53 -0700 (PDT) Received: from [192.168.1.36] (63.red-83-51-208.dynamicip.rima-tde.net. [83.51.208.63]) by smtp.gmail.com with ESMTPSA id c8sm14347292wmb.34.2021.04.12.03.47.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Apr 2021 03:47:52 -0700 (PDT) Subject: Re: [PATCH v4 for-6.0 05/12] esp: introduce esp_fifo_pop_buf() and use it instead of fifo8_pop_buf() To: Mark Cave-Ayland , qemu-devel@nongnu.org, alxndr@bu.edu, laurent@vivier.eu, pbonzini@redhat.com References: <20210407195801.685-1-mark.cave-ayland@ilande.co.uk> <20210407195801.685-6-mark.cave-ayland@ilande.co.uk> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Message-ID: <06ed2995-d11d-6c85-49dc-aaf1ad7f552f@amsat.org> Date: Mon, 12 Apr 2021 12:47:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210407195801.685-6-mark.cave-ayland@ilande.co.uk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 4/7/21 9:57 PM, Mark Cave-Ayland wrote: > The const pointer returned by fifo8_pop_buf() lies directly within the array used > to model the FIFO. Building with address sanitizers enabled shows that if the > caller expects a minimum number of bytes present then if the FIFO is nearly full, > the caller may unexpectedly access past the end of the array. > > Introduce esp_fifo_pop_buf() which takes a destination buffer and performs a > memcpy() in it to guarantee that the caller cannot overwrite the FIFO array and > update all callers to use it. Similarly add underflow protection similar to > esp_fifo_push() and esp_fifo_pop() so that instead of triggering an assert() > the operation becomes a no-op. > > Buglink: https://bugs.launchpad.net/qemu/+bug/1909247 > Signed-off-by: Mark Cave-Ayland > Tested-by: Alexander Bulekov > --- > hw/scsi/esp.c | 40 ++++++++++++++++++++++++++++------------ > 1 file changed, 28 insertions(+), 12 deletions(-) Way cleaner/safer. Reviewed-by: Philippe Mathieu-Daudé