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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E7097C3065C for ; Tue, 2 Jul 2024 21:05:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOkgw-0001WQ-Te; Tue, 02 Jul 2024 17:05:34 -0400 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 1sOkgv-0001WA-Dy for qemu-devel@nongnu.org; Tue, 02 Jul 2024 17:05:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sOkgs-0007jS-QA for qemu-devel@nongnu.org; Tue, 02 Jul 2024 17:05:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719954328; 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: in-reply-to:in-reply-to:references:references; bh=F4Lib4g++LzAE7jBfMQxUpgflaHVLvSvar6UT0dJREs=; b=PNA2G8Cq8FS7CQ8jw/EIK5gTXNjlZCTNoWp71OjBEfk3/l87Bgw1qDk8Y0flPEXE5+9sR2 +fwbilgYWfudqpecdI1EX0IP99m0gq1ZSGJzzEqcgD5h4y/kDohyAMU97fo2xvbmxGPiLV uA9aV6gO2c0Z3X2O4emGZQxHX+57FhU= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-562-L6NcIGHsN7ausY8avlJOEA-1; Tue, 02 Jul 2024 17:05:27 -0400 X-MC-Unique: L6NcIGHsN7ausY8avlJOEA-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3678e549a1eso380412f8f.0 for ; Tue, 02 Jul 2024 14:05:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719954325; x=1720559125; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=F4Lib4g++LzAE7jBfMQxUpgflaHVLvSvar6UT0dJREs=; b=IwTidykmLXjQjaaR/CdjLPDlJGO9AjGGHfSwNgTBxsl4FOqN9wv8dcydvhz2neJiK2 sJovrhtkAsr/wjONU5IFWKS+LmbgzalqZv3HnmA7VIXhCBnkqgSTpJZPH7KQEvAyOF0G Xc5vUno2LpnvxSCv/iTDU2X6Wcb6mTKRSgo+2eYDT8UH3+d7cm5wp59F/jQWTs+sVGSj oT6l/vfRam9y3WXofQc72XxP1HgI7TKSuZwtvXqNly6L6ca7U92o+Fmz69XJN4JIs4zD 6vSVH1WS5WUjhK/0dfCRvaMhPa6TKHYQ04+HSImmHgTUwGj2jQJhlZuQ4YzUf+DBWT09 bqXg== X-Forwarded-Encrypted: i=1; AJvYcCVoi24rmw8aPvFwvPDpDWFXO32z5sbeZbFCHdTU5G3PI+TIBCz6MviGAoByinZNjPZ4RTBa3SSteYsLl5KO+FYLq8FvxC8= X-Gm-Message-State: AOJu0Yw3ZfG9fFjvyFTHGM6SFQj7ZDichj9DviCMsESJz4eVzoju6zVy l5YVC9x0QFrJwDhaAFeaKPs4EfERSHKshioRqTD0jOuBn8avCuSSziwCHbIMPFutGIfUOHoq6rC nVQ0kQpYvlrSyzvTsIr+0BgYaUi0N5Ca6jd7R04f/kGZZosRavr9vKdYovTRR X-Received: by 2002:a5d:524a:0:b0:360:866f:5083 with SMTP id ffacd0b85a97d-36774f9375bmr8132893f8f.32.1719954325752; Tue, 02 Jul 2024 14:05:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEh77O4rNExg/juR7RshCk2KhmEi5wv+LuLCisrtcBzhomrb6dxP5VYp01BJAFm3hXXU1e5xg== X-Received: by 2002:a5d:524a:0:b0:360:866f:5083 with SMTP id ffacd0b85a97d-36774f9375bmr8132869f8f.32.1719954325011; Tue, 02 Jul 2024 14:05:25 -0700 (PDT) Received: from redhat.com ([2a02:14f:1f5:eadd:8c31:db01:9d01:7604]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a112a54sm14174980f8f.115.2024.07.02.14.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 14:05:24 -0700 (PDT) Date: Tue, 2 Jul 2024 17:05:19 -0400 From: "Michael S. Tsirkin" To: Zheyu Ma Cc: "Gonglei (Arei)" , qemu-devel@nongnu.org Subject: Re: [PATCH] hw/virtio/virtio-crypto: Fix op_code assignment in virtio_crypto_create_asym_session Message-ID: <20240702170444-mutt-send-email-mst@kernel.org> References: <20240702210227.3059947-1-zheyuma97@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240702210227.3059947-1-zheyuma97@gmail.com> Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.29 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org On Tue, Jul 02, 2024 at 11:02:27PM +0200, Zheyu Ma wrote: > The assignment of the op_code in the virtio_crypto_create_asym_session > function was moved before its usage to ensure it is correctly set. > Previously, if the function failed during the key_len check, the op_code when you say Previously, you mean "currently"? > did not have a proper value, causing virtio_crypto_free_create_session_req and here did not -> does not. > to not free the memory correctly, leading to a memory leak. > > By setting the op_code before performing any checks, we ensure that > virtio_crypto_free_create_session_req has the correct context to > perform cleanup operations properly, thus preventing memory leaks. > > ASAN log: > ==3055068==ERROR: LeakSanitizer: detected memory leaks > Direct leak of 512 byte(s) in 1 object(s) allocated from: > #0 0x5586a75e6ddd in malloc llvm/compiler-rt/lib/asan/asan_malloc_linux.cpp:129:3 > #1 0x7fb6b63b6738 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x5e738) > #2 0x5586a864bbde in virtio_crypto_handle_ctrl hw/virtio/virtio-crypto.c:407:19 > #3 0x5586a94fc84c in virtio_queue_notify_vq hw/virtio/virtio.c:2277:9 > #4 0x5586a94fc0a2 in virtio_queue_host_notifier_read hw/virtio/virtio.c:3641:9 > > Signed-off-by: Zheyu Ma > --- > hw/virtio/virtio-crypto.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c > index bbe8aa4b99..5034768bff 100644 > --- a/hw/virtio/virtio-crypto.c > +++ b/hw/virtio/virtio-crypto.c > @@ -205,6 +205,7 @@ virtio_crypto_create_asym_session(VirtIOCrypto *vcrypto, > int queue_index; > uint32_t algo, keytype, keylen; > > + sreq->info.op_code = opcode; > algo = ldl_le_p(&sess_req->para.algo); > keytype = ldl_le_p(&sess_req->para.keytype); > keylen = ldl_le_p(&sess_req->para.keylen); > @@ -224,7 +225,6 @@ virtio_crypto_create_asym_session(VirtIOCrypto *vcrypto, > iov_discard_front(&iov, &out_num, keylen); > } > > - sreq->info.op_code = opcode; > asym_info = &sreq->info.u.asym_sess_info; > asym_info->algo = algo; > asym_info->keytype = keytype; > -- > 2.34.1