From patchwork Sat Jun 19 17:26:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463885 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp1022708jao; Sat, 19 Jun 2021 10:36:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1osOjSIh4pCi33zDkOtHEyFkHA7d1u9GtAXwTRQRIXw/N8YaeZyA8RDNmIEvGRdXXsKMt X-Received: by 2002:a92:b50d:: with SMTP id f13mr11618148ile.253.1624124183277; Sat, 19 Jun 2021 10:36:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624124183; cv=none; d=google.com; s=arc-20160816; b=sCwGX5lniRzy+AIRrfMPo+SuzmMTFKyoN2zpyeCIAjfCRgOGCP+jU/eITHeKdeOYc2 ZMJQ/GRxDmNRi61zQgEMCg9N1kcpJmVl6sHWef9LBPo/yu+myH/weQZTVtjFSSXShsAn vqF9DB5GeESRAL0Q8CBLK6G+q/kkyZOKY2qpvZikP1m9nBk55S3VdS73zeeFUkYofpDB bwROZkM/4vG3RJ069gAuwD/c1nfPAD1c3agh7o62GkauDamEysBBckxBbxcBYPqKi7hd HCpHGJ3sVTimtvd7/xmuispsfErYdyLK41I/iQMGTiPgbyasx/sPoB4qjeTR93G9XdI9 Fpmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=v8CiO3nSkXbT0WhEZ00oCKiNO74Wj3K+LBYSZKxDzQk=; b=fU1dUY8Gx+EgDlapAfOpPdmAeHO3b77RGcdu5BcBEbIafC+BNPQJMGWSzxlak825qG LxVf/I2tCAu6NCQ2ECo3ktyKLhG+FzmLzCeWS5hYjTqS3DjLWmt9+pt1CHeSt/pZCk34 fg8yB7jUpAixM9wfdH7cgknVA+Y5brHJKAVZ5PJy2jV9I52CTaZ+TO693Xtekqs/v1rG XaG7tO6Xb8QVy86ifJkIBSwqT7cBliWV0//DhfQfQBBezVr/vKLFlQvRp8eifoZqqpe2 z19yIP8mZHtIpp18+HYo8ZbY0MQac1ADeNDV8YmtwEPyX1rbA19ya2BxglkuFcJupQSb ufCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=a60ao3De; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b19si14411608iow.46.2021.06.19.10.36.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 19 Jun 2021 10:36:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=a60ao3De; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luetK-0004Ue-NQ for patch@linaro.org; Sat, 19 Jun 2021 13:36:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luejw-0003g8-15 for qemu-devel@nongnu.org; Sat, 19 Jun 2021 13:26:40 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:45948) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luejt-0003cq-TT for qemu-devel@nongnu.org; Sat, 19 Jun 2021 13:26:39 -0400 Received: by mail-pf1-x429.google.com with SMTP id k6so10268802pfk.12 for ; Sat, 19 Jun 2021 10:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v8CiO3nSkXbT0WhEZ00oCKiNO74Wj3K+LBYSZKxDzQk=; b=a60ao3DebrBOIqT41FxhejwwcY/LtElXJ0RCsU0qFxL77fE8buGmBybmX/sl8WReHM nkofI/nzJpkR7C4lzGfyzUcXHk5kJNC1uqvqgfpLSr2URrkcizSEmzSK6QKwDJh4b8gn Ku3wZ5wcBRYdqIsuOYaw4B7cIdYKL6xxGqw/Xx6S/rTk19CPe8LbtuX4Vxh5ytknGnBX Qp+d7O9uoyLInxOko6tzsy/rFAzmK3KL12IABCVJJvCgdyiUy4FJZh53SBWwtcA1WwLD wpBhE9oHpOeRbzakW+VgBet0cRsun13PH2RLWK9oa4yWePL2seiwSbJBjM063xDW61Go qY9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v8CiO3nSkXbT0WhEZ00oCKiNO74Wj3K+LBYSZKxDzQk=; b=ucvcXZORu+sEN9bQHAMlIe1FDmgiDWlKGtZzRAx7JQuzFraMFuBB3Pvsx1TSqXB4oq 1rHar4YekhfE5U4Ea9JJISn00JhcTRf8CSpK3BpuMbrLYbsee9GVwT46oc6AaINhZQbV kWHZAxng08U08I19KN0whMLo9rCUt41xYFssQfzW8r2gTINXnXbXtCrhBqibB1MTnFRW o2/ejHEMHkL63HjFf9wShLgwmW8XRX12sZdnsZPHXZU7Z4y/jgq+aX3K9P8HL8266jKG qYp5msiMsGZpFnminLY8xyhnXWjlmpqzA81kCnIDfdtpf4CcAiRRdA4xUQxkpSitOzx3 1o4A== X-Gm-Message-State: AOAM530FL+q2OwoKoCxmEsVV8fC0ZVPQdu24R5w7RRPe+y4aQPINlEot S0lmBPlo52et8049hFWjpfcp8QQbLAX69A== X-Received: by 2002:a05:6a00:797:b029:2f9:6ddb:9d5e with SMTP id g23-20020a056a000797b02902f96ddb9d5emr10840439pfu.35.1624123596697; Sat, 19 Jun 2021 10:26:36 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id co18sm2084241pjb.37.2021.06.19.10.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Jun 2021 10:26:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 13/15] softmmu/memory: Disallow short writes Date: Sat, 19 Jun 2021 10:26:24 -0700 Message-Id: <20210619172626.875885-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619172626.875885-1-richard.henderson@linaro.org> References: <20210619172626.875885-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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 autolearn=ham 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: , Cc: alex.bennee@linaro.org, pbonzini@redhat.com, mark.cave-ayland@ilande.co.uk, f4bug@amsat.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Writes smaller than impl.min_access_size would require a read-modify-write cycle, which could have side effects. The present behaviour seems to be to extend the current write to min_access_size. While we could continue that, so far all of the instances I have seen have been either device model errors or the fuzzer intentionally doing bad things. Signed-off-by: Richard Henderson --- softmmu/memory.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) -- 2.25.1 diff --git a/softmmu/memory.c b/softmmu/memory.c index 7373d89600..2fe237327d 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -548,6 +548,26 @@ static MemTxResult access_with_adjusted_size(hwaddr addr, } /* FIXME: support unaligned access? */ + /* + * Check for a small access. + */ + if (unlikely(size < access_size_min)) { + /* + * Logically, we cannot support short writes without a read-modify + * cycle, and many mmio registers have side-effects on read. + * In practice, this appears to be either (1) model error, + * or (2) guest error via the fuzzer. + */ + if (write) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: Invalid short write: %s " + "hwaddr: 0x%" HWADDR_PRIx " size: %u " + "min: %u max: %u\n", __func__, + memory_region_name(mr), addr, size, + access_size_min, access_size_max); + return MEMTX_ERROR; + } + } + access_size = MAX(MIN(size, access_size_max), access_size_min); access_mask = MAKE_64BIT_MASK(0, access_size * 8); if (memory_region_big_endian(mr)) {