Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1282210pxy; Thu, 29 Apr 2021 03:48:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2S++x8uJbVhDftoFelWkZLoDZn+dPMPk6DuzXXOmnpmBHrMV9ZaWr/qBGfY+HWi7TAc1p X-Received: by 2002:a63:c6:: with SMTP id 189mr30060552pga.216.1619693298020; Thu, 29 Apr 2021 03:48:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619693298; cv=none; d=google.com; s=arc-20160816; b=KGH0xYC3lHn64rlmRjRPvD/TZAL4O0s/4Ek8lcKKRgNmrRc/Iuackm4PGmLQzpSAdI P7qALTtXsnz4oEQSmn16m+Qvj9fYAmAaJhlT8BgsKXKmmIkvAVIfkwQlk7Ol0nohBC/L 90Zm1vG978JR285S5PfREA+e7TcMlE5GMsAMk6Wic3zbE/IeRwY+GQGmRgc5L+LoB+Ng hnno4CSFCEklcqbYv9EQ941XyWNNFJVmuZFyn0NlLWfK1dcZ9FO7rn4L6d/yF7T5Gjrc oN5rj65Mov3ZmYfZXJWkcRG3LJ8VwQFdiiz6/DCRl6UZPiB5ZlpBKuO1dTXZaVLVL6Ps qrwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=UXTa4ZE9gpkhCU4NWG0Xq0wZu8R2ZGOnPbGvPkV96d4=; b=wrkGPK72I4YP52O8rKWEHYaibDXoDDBpu1g9SMWsZ/Z7ZFjE5WJIk4LCwHalvb6akw 0Flx9wged4iPk8G3yhGgteVmYiPvfIxyeT6d+e1ObyeWIOvPLGVuQgjkCN4K0cw7pgvD vhmmzcHeG+dCuWQlBlPXMyk0FodfxhbabJKKBMHR95EubcTaLV/vN/CpGQHTdpvCV8aK +H9TKMFC0AAy0VQBh4c8XJQ2BIWmRYbroUQhIeR5rauTJY8SJ48CV6nKdJ2p12JOBuBs Yah9Ai62agesWBAOq/xoRaYODBkdqZtj6TUQ0bjPnNzq14QHYfPLS/2A5O3Se7+b24fI KhDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g17si3256993pge.164.2021.04.29.03.48.03; Thu, 29 Apr 2021 03:48:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237051AbhD2Kqu (ORCPT + 99 others); Thu, 29 Apr 2021 06:46:50 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:41312 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232245AbhD2Kqu (ORCPT ); Thu, 29 Apr 2021 06:46:50 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lc4BG-00084q-EX; Thu, 29 Apr 2021 10:46:02 +0000 From: Colin King To: Jens Axboe , Pavel Begunkov , io-uring@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next][V2] io_uring: Fix premature return from loop and memory leak Date: Thu, 29 Apr 2021 11:46:02 +0100 Message-Id: <20210429104602.62676-1-colin.king@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King Currently the -EINVAL error return path is leaking memory allocated to data. Fix this by not returning immediately but instead setting the error return variable to -EINVAL and breaking out of the loop. Kudos to Pavel Begunkov for suggesting a correct fix. Signed-off-by: Colin Ian King --- V2: set ret/err to -EINVAL and break rather than kfree and return, fix both occurrences of this issue. --- fs/io_uring.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 47c2f126f885..c783ad83f220 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8417,8 +8417,10 @@ static int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg, ret = io_buffer_validate(&iov); if (ret) break; - if (!iov.iov_base && tag) - return -EINVAL; + if (!iov.iov_base && tag) { + ret = -EINVAL; + break; + } ret = io_sqe_buffer_register(ctx, &iov, &ctx->user_bufs[i], &last_hpage); @@ -8468,8 +8470,10 @@ static int __io_sqe_buffers_update(struct io_ring_ctx *ctx, err = io_buffer_validate(&iov); if (err) break; - if (!iov.iov_base && tag) - return -EINVAL; + if (!iov.iov_base && tag) { + err = -EINVAL; + break; + } err = io_sqe_buffer_register(ctx, &iov, &imu, &last_hpage); if (err) break; -- 2.30.2