Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3573452pxb; Mon, 24 Jan 2022 12:33:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3TlXWn9areUgEIpiqamBdZikxgItxu9CO7zSySaS4Y84E/d6LVaATUje3GNmxjMPo3h2n X-Received: by 2002:a17:902:6e17:b0:14b:702:4c5d with SMTP id u23-20020a1709026e1700b0014b07024c5dmr16371026plk.88.1643056278946; Mon, 24 Jan 2022 12:31:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643056278; cv=none; d=google.com; s=arc-20160816; b=tmIEkSCXf04p+FizMGdWtPAFp2GqOhqN3+qRi7ALK0w25eYtif5YSmNwz2LTi2fZud 4oeL1cuDQqtdh8zGv2ax3tGIYv8Ftf2M2BOCfbddA4lcpaLFds0SmaF+PuzyN6NVfaq3 9DueQNz5DfBeagf+KIQ60OmCIS0YXh+rK96Y1sLX7YFY4c1GEtkUHMrmWeufpP2zlgCN 5zeFeJ13+Pgff4KyKvik1V5mwyvmAvZx8kbxbjll2Z6rkIEiFUwb21VpdvZjpXVTfwTz 5qkR+IfRsXmDhirOzYxaRkzH+/YbmKhKkmjsOzSjUS9UD0SG1zHZYtWAZQlPP3zMPNeW HQtA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zyGzRg0+VQbNIewIiRQiFoC2l8MWGu85+uay3nIJEgs=; b=szRzu47SFTfDHjfKhI74mWJsWs/5NTSO/ew4gqjPjTfQsPppZw8XBxWTtRGNBcCTP7 uTsQvjUW4MnRajgpT3zxbrp+B/lbNJfZiVcMobHytZZEu1j7jwUsNDQN9rdeqRZBVBxu fqwHwOdXRuIDTRDry4BYGMTwWEyX90B5GQ3OylOgf7z+ScMd3NGsxUhfQoNFMKyVrPkh +Upl09l5TclLNA8Ke1WhYTW/uvAC1C8OqZfXMvYMGO0Q4pjCzX3P7QnynLtJgPLI/RCf wSezVtpd/x/rnUdLotguSHrVPG0GZjwDKcrrFlGthut0i1nitetiAdlA80k6KsJvEtp9 LR5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SiFyuThU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l13si9615670pls.571.2022.01.24.12.31.05; Mon, 24 Jan 2022 12:31:18 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SiFyuThU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354546AbiAXTgp (ORCPT + 99 others); Mon, 24 Jan 2022 14:36:45 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:57134 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242058AbiAXTbv (ORCPT ); Mon, 24 Jan 2022 14:31:51 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B9840614F0; Mon, 24 Jan 2022 19:31:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95700C340E5; Mon, 24 Jan 2022 19:31:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052710; bh=rD5AOzkXpRUJUGlmyD4mjgmBS/IZeXJBNqa5eZZZftQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SiFyuThU5MbVToAAB0c6JJLKtr4Aycv/P6T1gx1xFongMIedCGxgFByAcF1Kf5CCa Peg7cPzshqGZTI4+Paj9nl+BpCgIcobKF3OeDN5c+PML9/YjQWrB3V4U3Wb7h80ap+ 95B/W2vgVbYg0s+TNP+v2Dola/9v4nmUOUDPHIEM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Christian Brauner , Todd Kjos , Sasha Levin Subject: [PATCH 5.4 132/320] binder: fix handling of error during copy Date: Mon, 24 Jan 2022 19:41:56 +0100 Message-Id: <20220124183958.155863213@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@linuxfoundation.org> User-Agent: quilt/0.66 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: Todd Kjos [ Upstream commit fe6b1869243f23a485a106c214bcfdc7aa0ed593 ] If a memory copy function fails to copy the whole buffer, a positive integar with the remaining bytes is returned. In binder_translate_fd_array() this can result in an fd being skipped due to the failed copy, but the loop continues processing fds since the early return condition expects a negative integer on error. Fix by returning "ret > 0 ? -EINVAL : ret" to handle this case. Fixes: bb4a2e48d510 ("binder: return errors from buffer copy functions") Suggested-by: Dan Carpenter Acked-by: Christian Brauner Signed-off-by: Todd Kjos Link: https://lore.kernel.org/r/20211130185152.437403-2-tkjos@google.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/android/binder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 0512af0f04646..b9fb2a9269443 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -2660,8 +2660,8 @@ static int binder_translate_fd_array(struct binder_fd_array_object *fda, if (!ret) ret = binder_translate_fd(fd, offset, t, thread, in_reply_to); - if (ret < 0) - return ret; + if (ret) + return ret > 0 ? -EINVAL : ret; } return 0; } -- 2.34.1