Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3702628pxb; Mon, 24 Jan 2022 15:48:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUIfAjtUi1bcHqdC5fjuAUq6x012BR+fBxgA99JuWhSbQtiu/G8dpzwILxlb+nO4S8kKfG X-Received: by 2002:a63:120b:: with SMTP id h11mr13168076pgl.611.1643068132640; Mon, 24 Jan 2022 15:48:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068132; cv=none; d=google.com; s=arc-20160816; b=GzENMEqcqlmz+G/T0k/eTp0CJSA01AhKkcXkL/xsqOAat2eg5dxpzryVILT7dBCq/i TUHuhpBbouuYYDZGtFdDOI7W3SrQ59lgp304BZz/tf2gMUe4e78K9eIcRyN/NmAH1BbY My3uC8SVbZALjsJYQXm4gbw/gIt5sqNAEnpLP+HkzCXVUX8aLVr41uqU9q0hd7kIfzIc eB8c35kuAMUyrp5xArbouvI8N0xYRReiGMt8NhACULAt+/GxwqB0LJu1t4KFwECyU5TC jVl882QuKOtRh7pq/CLe2GoQnxCX2Sc+FfkmZzo57mNwL4kthTYiQxSkovenrtPee26K S9zA== 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=OmRyQiz/c5ZdLzMlqzN/qP+tPGIO04kWBNNKuoOWA6w=; b=SBB0fKsGVRbZ1+Ul7Vp3GlMXT3KzY50JGTSmQZZrI0toX0VAJSorGk8QgPcMirRrUr pRN7rLpOyl/lA88s5+CkMjedzODJxT+HhJELndnIiFEyHHWSljkCkNm+JMNMIFWBjeyw tey0RIZZgqzJ4ohwEPp6og2lkgaa6ihav2mgLSiT/Zpd862/Nbu1U7oOJwraVog97rzo 9zlMrafkU0f0NfOEulrCOAfJzYOjJqf7dMdvRSIWVp5wVgGqIkoNg4vFUmt7b6JdmkcO acJjObVY0Gtyicl9EZzczPNU28WiGPjZHmu4ctqOJ5sWvC2gRiOZCwmtksSYfO5+8MMF CqTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uphsUpec; 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 t16si601642pji.152.2022.01.24.15.48.41; Mon, 24 Jan 2022 15:48:52 -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=uphsUpec; 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 S2362898AbiAXXnI (ORCPT + 99 others); Mon, 24 Jan 2022 18:43:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383095AbiAXXFt (ORCPT ); Mon, 24 Jan 2022 18:05:49 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13B47C029806; Mon, 24 Jan 2022 13:16:44 -0800 (PST) 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 A7B27614A2; Mon, 24 Jan 2022 21:16:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CD62C340E4; Mon, 24 Jan 2022 21:16:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059003; bh=b/4IslJBEQd84GWcAJuYmPtCMrf3yVEFUlsk8XYbfeA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uphsUpec/0KhYBHVUtps8afSOuABs0ddABO6DxCIkaa4dZNHHk8P9fHoUrE8KT00+ 4SFEm9CmdRibr7el0cKkLfYruF4yMECMhXYvLULR5xAd2e8IuqArgObN2bhgZffM0F PaV4lcsyrbYe0e8zEWleAodEEhqfJ1k/KYML7m+I= 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.16 0471/1039] binder: fix handling of error during copy Date: Mon, 24 Jan 2022 19:37:40 +0100 Message-Id: <20220124184141.109754699@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 c75fb600740cc..7d29d3d931a79 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -2269,8 +2269,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