Skip to content

Commit b25db38

Browse files
prabhakarladmchehab
authored andcommitted
media: platform: davinci: drop VPFE_CMD_S_CCDC_RAW_PARAMS
drop VPFE_CMD_S_CCDC_RAW_PARAMS ioctl from dm355/dm644x following reasons: - This ioctl was never in public api and was only defined in kernel header. - The function set_params constantly mixes up pointers and phys_addr_t numbers. - This is part of a 'VPFE_CMD_S_CCDC_RAW_PARAMS' ioctl command that is described as an 'experimental ioctl that will change in future kernels'. - The code to allocate the table never gets called after we copy_from_user the user input over the kernel settings, and then compare them for inequality. - We then go on to use an address provided by user space as both the __user pointer for input and pass it through phys_to_virt to come up with a kernel pointer to copy the data to. This looks like a trivially exploitable root hole. Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
1 parent da05d52 commit b25db38

6 files changed

Lines changed: 4 additions & 346 deletions

File tree

‎drivers/media/platform/davinci/ccdc_hw_device.h‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ struct ccdc_hw_ops {
4242
int (*set_hw_if_params) (struct vpfe_hw_if_param *param);
4343
/* get interface parameters */
4444
int (*get_hw_if_params) (struct vpfe_hw_if_param *param);
45-
/*
46-
* Pointer to function to set parameters. Used
47-
* for implementing VPFE_S_CCDC_PARAMS
48-
*/
49-
int (*set_params) (void *params);
50-
/*
51-
* Pointer to function to get parameter. Used
52-
* for implementing VPFE_G_CCDC_PARAMS
53-
*/
54-
int (*get_params) (void *params);
5545
/* Pointer to function to configure ccdc */
5646
int (*configure) (void);
5747

‎drivers/media/platform/davinci/dm355_ccdc.c‎

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
* This module is for configuring DM355 CCD controller of VPFE to capture
1818
* Raw yuv or Bayer RGB data from a decoder. CCDC has several modules
1919
* such as Defect Pixel Correction, Color Space Conversion etc to
20-
* pre-process the Bayer RGB data, before writing it to SDRAM. This
21-
* module also allows application to configure individual
22-
* module parameters through VPFE_CMD_S_CCDC_RAW_PARAMS IOCTL.
23-
* To do so, application include dm355_ccdc.h and vpfe_capture.h header
24-
* files. The setparams() API is called by vpfe_capture driver
25-
* to configure module parameters
20+
* pre-process the Bayer RGB data, before writing it to SDRAM.
2621
*
2722
* TODO: 1) Raw bayer parameter settings and bayer capture
2823
* 2) Split module parameter structure to module specific ioctl structs
@@ -260,90 +255,6 @@ static void ccdc_setwin(struct v4l2_rect *image_win,
260255
dev_dbg(ccdc_cfg.dev, "\nEnd of ccdc_setwin...");
261256
}
262257

263-
static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
264-
{
265-
if (ccdcparam->datasft < CCDC_DATA_NO_SHIFT ||
266-
ccdcparam->datasft > CCDC_DATA_SHIFT_6BIT) {
267-
dev_dbg(ccdc_cfg.dev, "Invalid value of data shift\n");
268-
return -EINVAL;
269-
}
270-
271-
if (ccdcparam->mfilt1 < CCDC_NO_MEDIAN_FILTER1 ||
272-
ccdcparam->mfilt1 > CCDC_MEDIAN_FILTER1) {
273-
dev_dbg(ccdc_cfg.dev, "Invalid value of median filter1\n");
274-
return -EINVAL;
275-
}
276-
277-
if (ccdcparam->mfilt2 < CCDC_NO_MEDIAN_FILTER2 ||
278-
ccdcparam->mfilt2 > CCDC_MEDIAN_FILTER2) {
279-
dev_dbg(ccdc_cfg.dev, "Invalid value of median filter2\n");
280-
return -EINVAL;
281-
}
282-
283-
if ((ccdcparam->med_filt_thres < 0) ||
284-
(ccdcparam->med_filt_thres > CCDC_MED_FILT_THRESH)) {
285-
dev_dbg(ccdc_cfg.dev,
286-
"Invalid value of median filter threshold\n");
287-
return -EINVAL;
288-
}
289-
290-
if (ccdcparam->data_sz < CCDC_DATA_16BITS ||
291-
ccdcparam->data_sz > CCDC_DATA_8BITS) {
292-
dev_dbg(ccdc_cfg.dev, "Invalid value of data size\n");
293-
return -EINVAL;
294-
}
295-
296-
if (ccdcparam->alaw.enable) {
297-
if (ccdcparam->alaw.gamma_wd < CCDC_GAMMA_BITS_13_4 ||
298-
ccdcparam->alaw.gamma_wd > CCDC_GAMMA_BITS_09_0) {
299-
dev_dbg(ccdc_cfg.dev, "Invalid value of ALAW\n");
300-
return -EINVAL;
301-
}
302-
}
303-
304-
if (ccdcparam->blk_clamp.b_clamp_enable) {
305-
if (ccdcparam->blk_clamp.sample_pixel < CCDC_SAMPLE_1PIXELS ||
306-
ccdcparam->blk_clamp.sample_pixel > CCDC_SAMPLE_16PIXELS) {
307-
dev_dbg(ccdc_cfg.dev,
308-
"Invalid value of sample pixel\n");
309-
return -EINVAL;
310-
}
311-
if (ccdcparam->blk_clamp.sample_ln < CCDC_SAMPLE_1LINES ||
312-
ccdcparam->blk_clamp.sample_ln > CCDC_SAMPLE_16LINES) {
313-
dev_dbg(ccdc_cfg.dev,
314-
"Invalid value of sample lines\n");
315-
return -EINVAL;
316-
}
317-
}
318-
return 0;
319-
}
320-
321-
/* Parameter operations */
322-
static int ccdc_set_params(void __user *params)
323-
{
324-
struct ccdc_config_params_raw ccdc_raw_params;
325-
int x;
326-
327-
/* only raw module parameters can be set through the IOCTL */
328-
if (ccdc_cfg.if_type != VPFE_RAW_BAYER)
329-
return -EINVAL;
330-
331-
x = copy_from_user(&ccdc_raw_params, params, sizeof(ccdc_raw_params));
332-
if (x) {
333-
dev_dbg(ccdc_cfg.dev, "ccdc_set_params: error in copying ccdcparams, %d\n",
334-
x);
335-
return -EFAULT;
336-
}
337-
338-
if (!validate_ccdc_param(&ccdc_raw_params)) {
339-
memcpy(&ccdc_cfg.bayer.config_params,
340-
&ccdc_raw_params,
341-
sizeof(ccdc_raw_params));
342-
return 0;
343-
}
344-
return -EINVAL;
345-
}
346-
347258
/* This function will configure CCDC for YCbCr video capture */
348259
static void ccdc_config_ycbcr(void)
349260
{
@@ -939,7 +850,6 @@ static struct ccdc_hw_device ccdc_hw_dev = {
939850
.enable = ccdc_enable,
940851
.enable_out_to_sdram = ccdc_enable_output_to_sdram,
941852
.set_hw_if_params = ccdc_set_hw_if_params,
942-
.set_params = ccdc_set_params,
943853
.configure = ccdc_configure,
944854
.set_buftype = ccdc_set_buftype,
945855
.get_buftype = ccdc_get_buftype,

‎drivers/media/platform/davinci/dm644x_ccdc.c‎

Lines changed: 3 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717
* This module is for configuring CCD controller of DM6446 VPFE to capture
1818
* Raw yuv or Bayer RGB data from a decoder. CCDC has several modules
1919
* such as Defect Pixel Correction, Color Space Conversion etc to
20-
* pre-process the Raw Bayer RGB data, before writing it to SDRAM. This
21-
* module also allows application to configure individual
22-
* module parameters through VPFE_CMD_S_CCDC_RAW_PARAMS IOCTL.
23-
* To do so, application includes dm644x_ccdc.h and vpfe_capture.h header
24-
* files. The setparams() API is called by vpfe_capture driver
25-
* to configure module parameters. This file is named DM644x so that other
26-
* variants such DM6443 may be supported using the same module.
20+
* pre-process the Raw Bayer RGB data, before writing it to SDRAM.
21+
* This file is named DM644x so that other variants such DM6443
22+
* may be supported using the same module.
2723
*
2824
* TODO: Test Raw bayer parameter settings and bayer capture
2925
* Split module parameter structure to module specific ioctl structs
@@ -216,96 +212,8 @@ static void ccdc_readregs(void)
216212
dev_notice(ccdc_cfg.dev, "\nReading 0x%x to VERT_LINES...\n", val);
217213
}
218214

219-
static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
220-
{
221-
if (ccdcparam->alaw.enable) {
222-
u8 max_gamma = ccdc_gamma_width_max_bit(ccdcparam->alaw.gamma_wd);
223-
u8 max_data = ccdc_data_size_max_bit(ccdcparam->data_sz);
224-
225-
if ((ccdcparam->alaw.gamma_wd > CCDC_GAMMA_BITS_09_0) ||
226-
(ccdcparam->alaw.gamma_wd < CCDC_GAMMA_BITS_15_6) ||
227-
(max_gamma > max_data)) {
228-
dev_dbg(ccdc_cfg.dev, "\nInvalid data line select");
229-
return -1;
230-
}
231-
}
232-
return 0;
233-
}
234-
235-
static int ccdc_update_raw_params(struct ccdc_config_params_raw *raw_params)
236-
{
237-
struct ccdc_config_params_raw *config_params =
238-
&ccdc_cfg.bayer.config_params;
239-
unsigned int *fpc_virtaddr = NULL;
240-
unsigned int *fpc_physaddr = NULL;
241-
242-
memcpy(config_params, raw_params, sizeof(*raw_params));
243-
/*
244-
* allocate memory for fault pixel table and copy the user
245-
* values to the table
246-
*/
247-
if (!config_params->fault_pxl.enable)
248-
return 0;
249-
250-
fpc_physaddr = (unsigned int *)config_params->fault_pxl.fpc_table_addr;
251-
fpc_virtaddr = (unsigned int *)phys_to_virt(
252-
(unsigned long)fpc_physaddr);
253-
/*
254-
* Allocate memory for FPC table if current
255-
* FPC table buffer is not big enough to
256-
* accommodate FPC Number requested
257-
*/
258-
if (raw_params->fault_pxl.fp_num != config_params->fault_pxl.fp_num) {
259-
if (fpc_physaddr != NULL) {
260-
free_pages((unsigned long)fpc_virtaddr,
261-
get_order
262-
(config_params->fault_pxl.fp_num *
263-
FP_NUM_BYTES));
264-
}
265-
266-
/* Allocate memory for FPC table */
267-
fpc_virtaddr =
268-
(unsigned int *)__get_free_pages(GFP_KERNEL | GFP_DMA,
269-
get_order(raw_params->
270-
fault_pxl.fp_num *
271-
FP_NUM_BYTES));
272-
273-
if (fpc_virtaddr == NULL) {
274-
dev_dbg(ccdc_cfg.dev,
275-
"\nUnable to allocate memory for FPC");
276-
return -EFAULT;
277-
}
278-
fpc_physaddr =
279-
(unsigned int *)virt_to_phys((void *)fpc_virtaddr);
280-
}
281-
282-
/* Copy number of fault pixels and FPC table */
283-
config_params->fault_pxl.fp_num = raw_params->fault_pxl.fp_num;
284-
if (copy_from_user(fpc_virtaddr,
285-
(void __user *)raw_params->fault_pxl.fpc_table_addr,
286-
config_params->fault_pxl.fp_num * FP_NUM_BYTES)) {
287-
dev_dbg(ccdc_cfg.dev, "\n copy_from_user failed");
288-
return -EFAULT;
289-
}
290-
config_params->fault_pxl.fpc_table_addr = (unsigned long)fpc_physaddr;
291-
return 0;
292-
}
293-
294215
static int ccdc_close(struct device *dev)
295216
{
296-
struct ccdc_config_params_raw *config_params =
297-
&ccdc_cfg.bayer.config_params;
298-
unsigned int *fpc_physaddr = NULL, *fpc_virtaddr = NULL;
299-
300-
fpc_physaddr = (unsigned int *)config_params->fault_pxl.fpc_table_addr;
301-
302-
if (fpc_physaddr != NULL) {
303-
fpc_virtaddr = (unsigned int *)
304-
phys_to_virt((unsigned long)fpc_physaddr);
305-
free_pages((unsigned long)fpc_virtaddr,
306-
get_order(config_params->fault_pxl.fp_num *
307-
FP_NUM_BYTES));
308-
}
309217
return 0;
310218
}
311219

@@ -339,29 +247,6 @@ static void ccdc_sbl_reset(void)
339247
vpss_clear_wbl_overflow(VPSS_PCR_CCDC_WBL_O);
340248
}
341249

342-
/* Parameter operations */
343-
static int ccdc_set_params(void __user *params)
344-
{
345-
struct ccdc_config_params_raw ccdc_raw_params;
346-
int x;
347-
348-
if (ccdc_cfg.if_type != VPFE_RAW_BAYER)
349-
return -EINVAL;
350-
351-
x = copy_from_user(&ccdc_raw_params, params, sizeof(ccdc_raw_params));
352-
if (x) {
353-
dev_dbg(ccdc_cfg.dev, "ccdc_set_params: error in copyingccdc params, %d\n",
354-
x);
355-
return -EFAULT;
356-
}
357-
358-
if (!validate_ccdc_param(&ccdc_raw_params)) {
359-
if (!ccdc_update_raw_params(&ccdc_raw_params))
360-
return 0;
361-
}
362-
return -EINVAL;
363-
}
364-
365250
/*
366251
* ccdc_config_ycbcr()
367252
* This function will configure CCDC for YCbCr video capture
@@ -489,32 +374,6 @@ static void ccdc_config_black_compense(struct ccdc_black_compensation *bcomp)
489374
regw(val, CCDC_BLKCMP);
490375
}
491376

492-
static void ccdc_config_fpc(struct ccdc_fault_pixel *fpc)
493-
{
494-
u32 val;
495-
496-
/* Initially disable FPC */
497-
val = CCDC_FPC_DISABLE;
498-
regw(val, CCDC_FPC);
499-
500-
if (!fpc->enable)
501-
return;
502-
503-
/* Configure Fault pixel if needed */
504-
regw(fpc->fpc_table_addr, CCDC_FPC_ADDR);
505-
dev_dbg(ccdc_cfg.dev, "\nWriting 0x%lx to FPC_ADDR...\n",
506-
(fpc->fpc_table_addr));
507-
/* Write the FPC params with FPC disable */
508-
val = fpc->fp_num & CCDC_FPC_FPC_NUM_MASK;
509-
regw(val, CCDC_FPC);
510-
511-
dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FPC...\n", val);
512-
/* read the FPC register */
513-
val = regr(CCDC_FPC) | CCDC_FPC_ENABLE;
514-
regw(val, CCDC_FPC);
515-
dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FPC...\n", val);
516-
}
517-
518377
/*
519378
* ccdc_config_raw()
520379
* This function will configure CCDC for Raw capture mode
@@ -569,9 +428,6 @@ static void ccdc_config_raw(void)
569428
/* Configure Black level compensation */
570429
ccdc_config_black_compense(&config_params->blk_comp);
571430

572-
/* Configure Fault Pixel Correction */
573-
ccdc_config_fpc(&config_params->fault_pxl);
574-
575431
/* If data size is 8 bit then pack the data */
576432
if ((config_params->data_sz == CCDC_DATA_8BITS) ||
577433
config_params->alaw.enable)
@@ -929,7 +785,6 @@ static struct ccdc_hw_device ccdc_hw_dev = {
929785
.reset = ccdc_sbl_reset,
930786
.enable = ccdc_enable,
931787
.set_hw_if_params = ccdc_set_hw_if_params,
932-
.set_params = ccdc_set_params,
933788
.configure = ccdc_configure,
934789
.set_buftype = ccdc_set_buftype,
935790
.get_buftype = ccdc_get_buftype,

0 commit comments

Comments
 (0)