Unverified Commit 86591467 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!12476 fix CVE-2024-40965

Merge Pull Request from: @ci-robot 
 
PR sync from: dinglongwei <dinglongwei1@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/HA6JWB46O3ASWQSNEA66JPAFCNZWPMEP/ 
fix CVE-2024-40965_OLK-6.6

Alexander Stein (1):
  i2c: lpi2c: Avoid calling clk_get_rate during transfer

Uwe Kleine-König (2):
  clk: Add a devm variant of clk_rate_exclusive_get()
  clk: Provide !COMMON_CLK dummy for devm_clk_rate_exclusive_get()


-- 
2.17.1
 
https://gitee.com/src-openeuler/kernel/issues/IACTBX 
 
Link:https://gitee.com/openeuler/kernel/pulls/12476

 

Reviewed-by: default avatarWeilong Chen <chenweilong@huawei.com>
Signed-off-by: default avatarZhang Peng <zhangpeng362@huawei.com>
parents 0c1529d2 cb4a5ba3
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -1030,6 +1030,25 @@ int clk_rate_exclusive_get(struct clk *clk)
}
EXPORT_SYMBOL_GPL(clk_rate_exclusive_get);

static void devm_clk_rate_exclusive_put(void *data)
{
	struct clk *clk = data;

	clk_rate_exclusive_put(clk);
}

int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk)
{
	int ret;

	ret = clk_rate_exclusive_get(clk);
	if (ret)
		return ret;

	return devm_add_action_or_reset(dev, devm_clk_rate_exclusive_put, clk);
}
EXPORT_SYMBOL_GPL(devm_clk_rate_exclusive_get);

static void clk_core_unprepare(struct clk_core *core)
{
	lockdep_assert_held(&prepare_lock);
+16 −3
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ struct lpi2c_imx_struct {
	__u8			*rx_buf;
	__u8			*tx_buf;
	struct completion	complete;
	unsigned long		rate_per;
	unsigned int		msglen;
	unsigned int		delivered;
	unsigned int		block_data;
@@ -207,9 +208,7 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx)

	lpi2c_imx_set_mode(lpi2c_imx);

	clk_rate = clk_get_rate(lpi2c_imx->clks[0].clk);
	if (!clk_rate)
		return -EINVAL;
	clk_rate = lpi2c_imx->rate_per;

	if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST)
		filt = 0;
@@ -590,6 +589,20 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
	if (ret)
		return ret;

	/*
	 * Lock the parent clock rate to avoid getting parent clock upon
	 * each transfer
	 */
	ret = devm_clk_rate_exclusive_get(&pdev->dev, lpi2c_imx->clks[0].clk);
	if (ret)
		return dev_err_probe(&pdev->dev, ret,
				     "can't lock I2C peripheral clock rate\n");

	lpi2c_imx->rate_per = clk_get_rate(lpi2c_imx->clks[0].clk);
	if (!lpi2c_imx->rate_per)
		return dev_err_probe(&pdev->dev, -EINVAL,
				     "can't get I2C peripheral clock rate\n");

	pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT);
	pm_runtime_use_autosuspend(&pdev->dev);
	pm_runtime_get_noresume(&pdev->dev);
+17 −0
Original line number Diff line number Diff line
@@ -201,6 +201,18 @@ bool clk_is_match(const struct clk *p, const struct clk *q);
 */
int clk_rate_exclusive_get(struct clk *clk);

/**
 * devm_clk_rate_exclusive_get - devm variant of clk_rate_exclusive_get
 * @dev: device the exclusivity is bound to
 * @clk: clock source
 *
 * Calls clk_rate_exclusive_get() on @clk and registers a devm cleanup handler
 * on @dev to call clk_rate_exclusive_put().
 *
 * Must not be called from within atomic context.
 */
int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk);

/**
 * clk_rate_exclusive_put - release exclusivity over the rate control of a
 *                          producer
@@ -274,6 +286,11 @@ static inline int clk_rate_exclusive_get(struct clk *clk)
	return 0;
}

static inline int devm_clk_rate_exclusive_get(struct device *dev, struct clk *clk)
{
	return 0;
}

static inline void clk_rate_exclusive_put(struct clk *clk) {}

#endif